Search code examples
c++socketsudpdatagrampoco-libraries

UDP Cannot Assign Requested Address


I want to open a Datagramsocket and send some packets to my network device. However when i use the following cood an exception is thrown saying: Cannot Assign Requested Address: 192.168.1.114:1900

Poco::Net::SocketAddress sa("192.168.1.114",1900);
Poco::Net::DatagramSocket dgs(sa);
std::string text = "hello";
dgs.sendBytes(text.data(),text.size());

What's the problem here. I also use a udp testing software to test the receiving end if it's capable to receive udp packets on this port and it works, however with the poco code from above it does not work.

kind regards


Solution

  • I don't know Poco but you must bind to a local address and port, then your sendto will send your packet from that local address:port to the remote address and port.