Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/network/udp_socket.h @ 9110

Last change on this file since 9110 was 8802, checked in by patrick, 18 years ago

merged the network branche back to trunk

File size: 1.4 KB
RevLine 
[7540]1/*!
2 * @file upd_socket.h
3 *  class to connect to other clients via udp
4 */
5
6#ifndef _UDP_SOCKET
7#define _UDP_SOCKET
8
9/* include this file, it contains some default definitions */
10#include "netdefs.h"
11
12
13/* include base_object.h since all classes are derived from this one */
14#include "network_socket.h"
15
16class UdpServerSocket;
17
[8802]18enum
19{
20  UDPCMD_DISCONNECT = 1,
21  UDPCMD_INVALIDRNDBYTE = 2
22};
23
[7540]24class UdpSocket : public NetworkSocket
25{
26  public:
27    UdpSocket();
[8802]28    UdpSocket( UdpServerSocket * serverSocket, IPaddress ip, int userId, byte randomByte );
[7540]29    UdpSocket( std::string host, int port );
30    virtual ~UdpSocket();
31
32    virtual void connectToServer( std::string host, int port );
33   
34    virtual void disconnectServer();
35
[8802]36    virtual bool writePacket(byte * data, int length );
[7540]37
38    virtual int readPacket(byte * data, int maxLength);
39   
40  private:
41    UdpServerSocket * serverSocket;   //!< will get packets here
42    int               userId;         //!< user id used by serverSocket
43    IPaddress         ip;             //!< host,port
44    UDPsocket         socket;         //!< socket used to send/recieve
45    UDPpacket *       packet;
46   
[8802]47    byte              randomByte;     //!< contains random bytes & 0xFC
48   
49    bool writeRawPacket( byte * data, int length );
50    bool checkUdpCmd( byte udpCmd );
51    bool checkRandomByte( byte rndByte );
52    byte generateNewRandomByte();
53   
[7540]54    void init();
55
56};
57
58
59
60#endif /* _NETWORK_SOCKET */
Note: See TracBrowser for help on using the repository browser.