[7540] | 1 | /*! |
---|
| 2 | * @file udp_server_socket.h |
---|
| 3 | * waits for incoming connections |
---|
| 4 | |
---|
| 5 | */ |
---|
| 6 | |
---|
| 7 | #ifndef _UDP_SERVER_SOCKET |
---|
| 8 | #define _UDP_SERVER_SOCKET |
---|
| 9 | |
---|
| 10 | /* include this file, it contains some default definitions */ |
---|
| 11 | #include "netdefs.h" |
---|
| 12 | |
---|
| 13 | |
---|
| 14 | /* include base_object.h since all classes are derived from this one */ |
---|
| 15 | #include "base_object.h" |
---|
| 16 | #include "server_socket.h" |
---|
| 17 | #include "udp_socket.h" |
---|
| 18 | |
---|
| 19 | #include <list> |
---|
| 20 | #include <vector> |
---|
| 21 | |
---|
[7575] | 22 | #define UDP_PACKET_SIZE 10240 |
---|
[7540] | 23 | #define MAX_NEW_CONNECTIONS 8 |
---|
| 24 | |
---|
| 25 | struct NetworkPacket |
---|
| 26 | { |
---|
| 27 | int length; |
---|
| 28 | byte * data; |
---|
| 29 | }; |
---|
| 30 | |
---|
| 31 | typedef std::list<NetworkPacket> NetworkPacketList; |
---|
| 32 | |
---|
| 33 | typedef std::vector<NetworkPacketList> PacketBuffer; |
---|
| 34 | |
---|
[8802] | 35 | struct UserInfo |
---|
| 36 | { |
---|
| 37 | IPaddress addr; |
---|
| 38 | byte randomByte; |
---|
| 39 | }; |
---|
[7540] | 40 | |
---|
[8802] | 41 | typedef std::vector<UserInfo> UserList; |
---|
| 42 | |
---|
[7540] | 43 | typedef std::list<UdpSocket*> UdpSocketList; |
---|
| 44 | |
---|
| 45 | class UdpServerSocket : public ServerSocket |
---|
| 46 | { |
---|
| 47 | public: |
---|
| 48 | UdpServerSocket( int port); |
---|
| 49 | |
---|
| 50 | virtual ~UdpServerSocket(); |
---|
| 51 | |
---|
| 52 | virtual bool listen( unsigned int port ); |
---|
| 53 | |
---|
| 54 | virtual NetworkSocket* getNewSocket( void ); |
---|
| 55 | |
---|
| 56 | virtual void close(); |
---|
| 57 | |
---|
[7565] | 58 | virtual void update(); |
---|
| 59 | |
---|
[7540] | 60 | void removeUserPackets( int userId ); |
---|
| 61 | void removeUser( int userId ); |
---|
| 62 | NetworkPacket getPacket( int userId ); |
---|
| 63 | bool sendPacket( NetworkPacket networkPacket, int userId ); |
---|
| 64 | int getPacketCount( int childId ); |
---|
[8802] | 65 | void initUser( int childId, IPaddress ip, byte randomByte ); |
---|
[7540] | 66 | |
---|
| 67 | private: |
---|
| 68 | UDPsocket socket; //!< will be uses to send/recieve data |
---|
| 69 | UDPpacket * packet; //!< packet structure to recieve packet |
---|
| 70 | PacketBuffer packetBuffer; //!< will store recieved packets for UdpSockets |
---|
| 71 | UserList userList; //!< contains information about clients |
---|
| 72 | UdpSocketList newSocketList; //!< contains new socket |
---|
| 73 | |
---|
| 74 | }; |
---|
| 75 | |
---|
| 76 | #endif |
---|