DatagramSocket send example in slides not working

Please post support and help requests here.
Posts: 1
Joined: 25 Sep 2013, 14:30

DatagramSocket send example in slides not working

Postby fatslug » 25 Sep 2013, 14:44


I don't know if I should post that here or on the issue tracker:
In the "Poco Network" pdf/slides, there's a sender example for the DatagramSocket (on page 15).

There's a couple of problems with it:
- First, there's a typo on the sendBytes() line. It should be:

Code: Select all

dgs.sendBytes(, syslogMsg.size());      // it's syslogMsg here, not msg

- Then, the sendBytes() method throws a "Socket is not connected" exception at runtime. I guess the socket should not be constructed with the address as it gets automatically bound to it. And also we should use the sendTo() method with the address, instead of the sendBytes() one.

Code: Select all

Poco::Net::DatagramSocket dgs;
std::string syslogMsg;
Poco::Timestamp now;
syslogMsg = Poco::DateTimeFormatter::format(now, "<14>%w %f %H:%M:%S Hello, world!");
Poco::Net::SocketAddress sa("localhost", 514);
dgs.sendTo(, syslogMsg.size(), sa);      

Is that the correct thing to do? (I'm still a bit confused with the binding/sending usage).

Anyway, thanks a lot for Poco, it's great!

Return to “Support”

Who is online

Users browsing this forum: No registered users and 2 guests