/*! * @file udp_server_socket.h * waits for incoming connections */ #ifndef _UDP_SERVER_SOCKET #define _UDP_SERVER_SOCKET /* include this file, it contains some default definitions */ #include "netdefs.h" /* include base_object.h since all classes are derived from this one */ #include "base_object.h" #include "server_socket.h" #include "udp_socket.h" #include #include #define UDP_PACKET_SIZE 10240 #define MAX_NEW_CONNECTIONS 8 struct NetworkPacket { int length; byte * data; }; typedef std::list NetworkPacketList; typedef std::vector PacketBuffer; //!< informations struct for each user struct UserInfo { IPaddress addr; //!< ip address of this user byte randomByte; //!< random byte of this user }; typedef std::vector UserList; typedef std::list UdpSocketList; //!< the upd server socket listening for incoming connections class UdpServerSocket : public ServerSocket { ObjectListDeclaration(UdpServerSocket); public: UdpServerSocket( int port); virtual ~UdpServerSocket(); /* server socket manipulations */ virtual bool listen( unsigned int port ); virtual NetworkSocket* getNewSocket( void ); virtual void close(); virtual void update(); /* network traffic interface */ NetworkPacket getPacket( int userId ); void removeUser( int userId ); bool sendPacket( NetworkPacket networkPacket, int userId ); private: void removeUserPackets( int userId ); int getPacketCount( int childId ); void initUser( int childId, IPaddress ip, byte randomByte ); private: UDPsocket socket; //!< will be used to send/recieve data to/from clients UDPpacket * packet; //!< packet structure to recieve packet PacketBuffer packetBuffer; //!< will store recieved packets for UdpSockets UserList userList; //!< contains information about clients UdpSocketList newSocketList; //!< contains new socket }; #endif