sot-talos-balance  2.0.5
Collection of dynamic-graph entities aimed at implementing balance control on talos.
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  public:
14  CNetwork();
15  ~CNetwork();
16  bool Connect(const char* pServerAddr, unsigned short nPort);
17  void Disconnect();
18  bool Connected() const;
19  bool CreateUDPSocket(unsigned short& nUDPPort, bool bBroadcast = false);
20  int Receive(char* rtDataBuff, int nDataBufSize, bool bHeader, int nTimeout,
21  unsigned int* ipAddr = nullptr);
22  bool Send(const char* pSendBuf, int nSize);
23  bool SendUDPBroadcast(const char* pSendBuf, int nSize, short nPort,
24  unsigned int nFilterAddr = 0);
25  char* GetErrorString();
26  int GetError() const;
27  bool IsLocalAddress(unsigned int nAddr) const;
28  unsigned short GetUdpServerPort();
29  unsigned short GetUdpBroadcastServerPort();
30 
31  private:
32  bool InitWinsock();
33  void SetErrorString();
34  unsigned short GetUdpServerPort(SOCKET nSocket);
35 
36  private:
37  SOCKET mSocket;
38  SOCKET mUDPSocket;
39  SOCKET mUDPBroadcastSocket;
40  char mErrorStr[256];
41  unsigned long mLastError;
42 };
43 
44 #endif
#define SOCKET
Definition: Network.h:9
int GetError() const
Definition: Network.cpp:434
bool IsLocalAddress(unsigned int nAddr) const
Definition: Network.cpp:436
bool Send(const char *pSendBuf, int nSize)
Definition: Network.cpp:313
~CNetwork()
Definition: Network.cpp:55
bool SendUDPBroadcast(const char *pSendBuf, int nSize, short nPort, unsigned int nFilterAddr=0)
Definition: Network.cpp:328
void Disconnect()
Definition: Network.cpp:141
unsigned short GetUdpBroadcastServerPort()
Definition: Network.cpp:219
int Receive(char *rtDataBuff, int nDataBufSize, bool bHeader, int nTimeout, unsigned int *ipAddr=nullptr)
Definition: Network.cpp:226
bool CreateUDPSocket(unsigned short &nUDPPort, bool bBroadcast=false)
Definition: Network.cpp:155
CNetwork()
Definition: Network.cpp:45
char * GetErrorString()
Definition: Network.cpp:432
bool Connected() const
Definition: Network.cpp:153
unsigned short GetUdpServerPort()
Definition: Network.cpp:215
bool Connect(const char *pServerAddr, unsigned short nPort)
Definition: Network.cpp:79