Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/network/udp_server_socket.h @ 9562

Last change on this file since 9562 was 9494, checked in by bensch, 18 years ago

merged the proxy back

File size: 2.0 KB
RevLine 
[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
25struct NetworkPacket
26{
27  int length;
28  byte * data;
29};
30
31typedef std::list<NetworkPacket> NetworkPacketList;
32
33typedef std::vector<NetworkPacketList> PacketBuffer;
34
[9494]35
36//!< informations struct for each user
[8802]37struct UserInfo
38{
[9494]39  IPaddress     addr;            //!< ip address of this user
40  byte          randomByte;      //!< random byte of this user
[8802]41};
[7540]42
[9494]43
[8802]44typedef std::vector<UserInfo> UserList;
45
[7540]46typedef std::list<UdpSocket*> UdpSocketList;
47
[9494]48
49//!< the upd server socket listening for incoming connections
[7540]50class UdpServerSocket : public ServerSocket
51{
52  public:
53    UdpServerSocket( int port);
54    virtual ~UdpServerSocket();
55
[9494]56    /* server socket manipulations */
[7540]57    virtual bool listen( unsigned int port );
58    virtual NetworkSocket* getNewSocket( void );
59    virtual void close();
[9246]60
[7565]61    virtual void update();
[9246]62
[9494]63    /* network traffic interface */
64    NetworkPacket getPacket( int userId );
[7540]65    void removeUser( int userId );
66    bool sendPacket( NetworkPacket networkPacket, int userId );
[9494]67
68
69  private:
70    void removeUserPackets( int userId );
[7540]71    int getPacketCount( int childId );
[8802]72    void initUser( int childId, IPaddress ip, byte randomByte );
[9246]73
[9494]74
[7540]75  private:
[9494]76    UDPsocket          socket;           //!< will be used to send/recieve data to/from clients
77    UDPpacket *        packet;           //!< packet structure to recieve packet
78    PacketBuffer       packetBuffer;     //!< will store recieved packets for UdpSockets
79    UserList           userList;         //!< contains information about clients
80    UdpSocketList      newSocketList;    //!< contains new socket
[7540]81
82};
83
84#endif
Note: See TracBrowser for help on using the repository browser.