OdinAI

- Main Page
- Namespaces
- Classes
- Files
- Examples

- File List

All Classes Namespaces Functions Variables
NetworkManager.h
1 #ifndef ODINAI_NETWORK_MANAGER_H_
2 #define ODINAI_NETWORK_MANAGER_H_
3
4 #ifdef _WIN32
5
6 #ifndef WIN32_LEAN_AND_MEAN
7 #define WIN32_LEAN_AND_MEAN
8 #endif
9
10 #pragma comment(lib, "Ws2_32.lib")
11
12 #include <windows.h>
13 #include <winsock2.h>
14 #include <ws2tcpip.h>
15 #include <iphlpapi.h>
16 #endif
17
18 #include <map>
19 #include <vector>
20 #include <functional>
21
22 #include "SharedDefs.h"
23
24 namespace OdinAI
25 {
26 typedef std::function<void(char*, int)> AsyncRecvCallback;
27
31 class NetworkManager
32 {
33 public:
34 NetworkManager() { }
35
40 bool Connect(const char *ip, const char *port, const AsyncRecvCallback &asyncRecvCallback);
41
45 void Update();
46
50 void Close();
51
55 void Send(const void *data, int size);
56 private:
60 void HandleReceive();
61
65 void HandleSend();
66
67 #ifdef _WIN32
68 SOCKET m_clientSocket;
69 WSAData m_wsaData;
70 WSAEVENT m_netEvent;
71 #else
72 int m_clientSocket;
73 #endif
74 AsyncRecvCallback m_asyncRecvCallback;
75
76 int m_currentInPos;
77 int m_currentOutPos;
78 char m_netBuffer[NETWORK_BUFFER_SIZE];
79 char m_outBuffer[NETWORK_BUFFER_SIZE];
80 bool m_bCanSend;
81 };
82 }
83
84 #endif
OdinAI::NetworkManager::Close
void Close()
OdinAI::NetworkManager::Update
void Update()
OdinAI::NetworkManager::Send
void Send(const void *data, int size)
OdinAI::NetworkManager
Definition: NetworkManager.h:31
OdinAI::NetworkManager::Connect
bool Connect(const char *ip, const char *port, const AsyncRecvCallback &asyncRecvCallback)