/* $Id: serverconnectiontcpudp.hpp,v 1.4 2005/12/02 23:34:23 chfreund Exp $ */ #ifndef _SERVERCONNECTIONTCPUDP_HPP_ #define _SERVERCONNECTIONTCPUDP_HPP_ #include #include #include #include "serverconnection.hpp" #include "serverentry.hpp" struct Message; struct EchoMessage; class World; class ServerConnectionTCP; //! A server connection class using TCP and UDP communication class ServerConnectionTCPUDP : public ServerConnection { private: //! The server entry RemoteServerEntry m_serverEntry; //! A TCP socket TCPsocket m_tcpSocket; //! A socket set SDLNet_SocketSet m_tcpSocketSet; //! The server address to send UDP packets to IPaddress m_udpAddress; //! A UDP socket UDPsocket m_udpSocket; //! A socket set for the UDP socket SDLNet_SocketSet m_udpSocketSet; //! These variables provide a range of UDP port numbers Uint16 m_udpPortStart; Uint16 m_udpPortEnd; //! The local used UDP port number Uint16 m_udpPort; //! UDP packet for outgoing events UDPpacket* m_eventPacket; //! UDP packet for incoming echos UDPpacket* m_echoPacket; //! A message queue for general messages std::deque m_messageQueue; //! A message queue for echo messages std::deque m_echoMessageQueue; //! A counter for the last received echo frame Uint32 m_lastReceivedFrame; //! Timestamp for the last received UDP message Uint32 m_lastUdpActivity; //! The world that is managed over this connection World* m_world; public: //! Constructor ServerConnectionTCPUDP( RemoteServerEntry& entry ); //! Destructor virtual ~ServerConnectionTCPUDP(); //! \name Implementations of abstract functions of the base class //@{ ServerEntry::Type getType() const { return ServerEntry::REMOTE; } bool checkConnection( ServerEntry* server ); bool openConnection(); void closeConnection(); bool checkUdpConnection(); void sendMessage( Message* message ); EchoMessage* getEchoMessage( Uint32 frame ); Message* popMessage(); Message* peekMessage(); //@} //! Morph the connection to a pure TCP connection ServerConnectionTCP* createServerConnectionTCP(); //! Get the world World* getWorld() { return m_world; } private: //! Receives messages from the server and stores them in the queues bool recvMessage(); bool recvEchoMessage(); }; #endif // _SERVERCONNECTIONTCPUDP_HPP_