Nidrax

UdpClient.h

Sep 5th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #ifndef UDP_CLIENT_H
  2. #define UDP_CLIENT_H
  3.  
  4. #include "ICommClient.h"
  5. #include <boost/asio.hpp>
  6. #include <boost/system/error_code.hpp>
  7.  
  8. using boost::asio::ip::udp;
  9. using boost::asio::ip::address;
  10.  
  11. // ReSharper disable once CppPolymorphicClassWithNonVirtualPublicDestructor
  12. class UdpClient : public ICommClient  // NOLINT
  13. {
  14. public:
  15.     UdpClient();
  16.     // ReSharper disable once CppHidingFunction
  17.     ~UdpClient();
  18.  
  19.     void Init(bool) override;
  20.     void Send(std::string) override;
  21.     boost::signals2::signal<void(std::string)> Incoming;
  22.  
  23. private:
  24.     boost::asio::io_service _ioServiceIn;
  25.     boost::shared_ptr<udp::socket> _socketIn;
  26.     udp::endpoint _endpointIn;
  27.     std::array<char, 1024> _bufferIn;
  28.  
  29.     boost::asio::io_service _ioServiceOut;
  30.     boost::shared_ptr<udp::socket> _socketOut;
  31.     udp::endpoint _endpointOut;
  32.  
  33.     void StartReceive();
  34.     void Receive(const boost::system::error_code& error, std::size_t bytesTransferred);
  35. };
  36.  
  37. #endif //UDP_CLIENT_H
Advertisement
Add Comment
Please, Sign In to add comment