diff options
Diffstat (limited to 'host/lib/transport')
-rw-r--r-- | host/lib/transport/udp_simple.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/host/lib/transport/udp_simple.cpp b/host/lib/transport/udp_simple.cpp index bc1bdaf2f..d6c55eae7 100644 --- a/host/lib/transport/udp_simple.cpp +++ b/host/lib/transport/udp_simple.cpp @@ -36,7 +36,7 @@ public: //resolve the address asio::ip::udp::resolver resolver(_io_service); asio::ip::udp::resolver::query query(asio::ip::udp::v4(), addr, port); - _receiver_endpoint = *resolver.resolve(query); + _send_endpoint = *resolver.resolve(query); //create and open the socket _socket = socket_sptr(new asio::ip::udp::socket(_io_service)); @@ -46,25 +46,30 @@ public: _socket->set_option(asio::socket_base::broadcast(bcast)); //connect the socket - if (connect) _socket->connect(_receiver_endpoint); + if (connect) _socket->connect(_send_endpoint); } size_t send(const asio::const_buffer &buff){ if (_connected) return _socket->send(asio::buffer(buff)); - return _socket->send_to(asio::buffer(buff), _receiver_endpoint); + return _socket->send_to(asio::buffer(buff), _send_endpoint); } size_t recv(const asio::mutable_buffer &buff, double timeout){ if (not wait_for_recv_ready(_socket->native(), timeout)) return 0; - return _socket->receive(asio::buffer(buff)); + return _socket->receive_from(asio::buffer(buff), _recv_endpoint); + } + + std::string get_recv_addr(void){ + return _recv_endpoint.address().to_string(); } private: bool _connected; asio::io_service _io_service; socket_sptr _socket; - asio::ip::udp::endpoint _receiver_endpoint; + asio::ip::udp::endpoint _send_endpoint; + asio::ip::udp::endpoint _recv_endpoint; }; /*********************************************************************** |