Question

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

Was it helpful?

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.

OTHER TIPS

Check the docs. Likely sa should be the local address and the remote address is to be specified somewhere else.

UDP doesn't have the notion of connection so there's no reason to bind the socket to a single remote address. A UDP socket can send and receive to/from any remote socket.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top