(C++)  1.1.0
A multi-platform, modular, universal engine for embedding advanced AI in games.
UDPServer.h
1 #ifndef GRAIL_UDPSERVER_H
2 #define GRAIL_UDPSERVER_H
3 
4 #include "../../libs/poco/Net/include/Poco/Net/DatagramSocket.h"
5 #include "../../libs/poco/Net/include/Poco/Net/SocketAddress.h"
6 #include "../../libs/poco/Net/include/Poco/Net/HostEntry.h"
7 
8 #include <string>
9 #include <map>
10 #include <memory>
11 #include <thread>
12 #include <cstddef>
13 
14 namespace grail
15 {
16  class UDPServer
17  {
18  public:
19  UDPServer(const std::string& appName, unsigned int serverPort, unsigned long bufferSize = 1024, bool sendFakeNames = false);
20  ~UDPServer();
21  void StartReceive(const Poco::Net::IPAddress& ipHost);
22 
23  private:
24  void RebuildInterfaces();
25  void CheckUDP();
26  void UDPChecker();
27 
28  constexpr static std::size_t ITERATIONS_BETWEEN_REBUILD{500};
29  constexpr static Poco::UInt16 UDP_LISTENER_PORT{6661};
30  const static std::string SEARCH_COMMAND;
31 
32  const std::string appName{""};
33  const unsigned int serverPort{0};
34  const bool sendFakeNames{false};
35  std::string hostName{""};
36 
37  std::unique_ptr<std::thread> udpCheckerThread{nullptr};
38 
39  std::vector<Poco::Net::IPAddress> interfaces{};
40  Poco::Net::HostEntry localHostEntry{};
41 
42  Poco::Net::SocketAddress anyAddress{};
43 
44  std::atomic<bool> isWorking{true};
45 
46  std::map<std::string, Poco::Net::DatagramSocket> sockets{};
47  char* buffer{nullptr};
48  unsigned long bufferSize;
49  };
50 }
51 
52 #endif // GRAIL_UDPSERVER_H
Definition: UDPServer.h:17