sot-talos-balance  1.6.0
Network.h
Go to the documentation of this file.
1 #ifndef NETWORK_H
2 #define NETWORK_H
3 
4 #ifdef _WIN32
5  #define WIN32_LEAN_AND_MEAN
6  #include <winsock2.h>
7 #else
8  #define INVALID_SOCKET -1
9  #define SOCKET int
10 #endif
11 
12 class CNetwork
13 {
14 public:
15  CNetwork();
16  ~CNetwork();
17  bool Connect(const char* pServerAddr, unsigned short nPort);
18  void Disconnect();
19  bool Connected() const;
20  bool CreateUDPSocket(unsigned short &nUDPPort, bool bBroadcast = false);
21  int Receive(char* rtDataBuff, int nDataBufSize, bool bHeader, int nTimeout, unsigned int *ipAddr = nullptr);
22  bool Send(const char* pSendBuf, int nSize);
23  bool SendUDPBroadcast(const char* pSendBuf, int nSize, short nPort, unsigned int nFilterAddr = 0);
24  char* GetErrorString();
25  int GetError() const;
26  bool IsLocalAddress(unsigned int nAddr) const;
27  unsigned short GetUdpServerPort();
28  unsigned short GetUdpBroadcastServerPort();
29 
30 private:
31  bool InitWinsock();
32  void SetErrorString();
33  unsigned short GetUdpServerPort(SOCKET nSocket);
34 
35 private:
36  SOCKET mSocket;
37  SOCKET mUDPSocket;
38  SOCKET mUDPBroadcastSocket;
39  char mErrorStr[256];
40  unsigned long mLastError;
41 };
42 
43 
44 #endif
int Receive(char *rtDataBuff, int nDataBufSize, bool bHeader, int nTimeout, unsigned int *ipAddr=nullptr)
Definition: Network.cpp:266
unsigned short GetUdpServerPort()
Definition: Network.cpp:254
bool CreateUDPSocket(unsigned short &nUDPPort, bool bBroadcast=false)
Definition: Network.cpp:176
void Disconnect()
Definition: Network.cpp:157
~CNetwork()
Definition: Network.cpp:57
int GetError() const
Definition: Network.cpp:514
unsigned short GetUdpBroadcastServerPort()
Definition: Network.cpp:259
bool Send(const char *pSendBuf, int nSize)
Definition: Network.cpp:374
char * GetErrorString()
Definition: Network.cpp:508
bool SendUDPBroadcast(const char *pSendBuf, int nSize, short nPort, unsigned int nFilterAddr=0)
Definition: Network.cpp:393
bool Connected() const
Definition: Network.cpp:171
CNetwork()
Definition: Network.cpp:45
bool Connect(const char *pServerAddr, unsigned short nPort)
Definition: Network.cpp:87
bool IsLocalAddress(unsigned int nAddr) const
Definition: Network.cpp:520
#define SOCKET
Definition: Network.h:9