26 #ifndef ODVA_ETHERNETIP_SOCKET_UDP_SOCKET_H 27 #define ODVA_ETHERNETIP_SOCKET_UDP_SOCKET_H 30 #include <boost/asio.hpp> 37 using boost::asio::ip::udp;
49 UDPSocket(io_service& io_serv,
unsigned short local_port, std::string local_ip=
"0.0.0.0")
50 : socket_(io_serv), local_endpoint_(boost::asio::ip::address::from_string(local_ip), local_port) { }
57 virtual void open(
string hostname,
string port)
59 udp::resolver resolver(socket_.get_io_service());
60 udp::resolver::query query(udp::v4(), hostname, port);
61 remote_endpoint_ = *resolver.resolve(query);
62 socket_.open(udp::v4());
63 socket_.bind(local_endpoint_);
79 virtual size_t send(const_buffer buf)
81 return socket_.send_to(const_buffers_1(buf), remote_endpoint_);
89 virtual size_t receive(mutable_buffer buf)
93 return socket_.receive_from(mutable_buffers_1(buf), ep);
104 #endif // ODVA_ETHERNETIP_SOCKET_UDP_SOCKET_H virtual size_t receive(mutable_buffer buf)
UDPSocket(io_service &io_serv, unsigned short local_port, std::string local_ip="0.0.0.0")
virtual void open(string hostname, string port)
udp::endpoint local_endpoint_
virtual size_t send(const_buffer buf)
udp::endpoint remote_endpoint_