Overview
Features
Download
Documentation
Community
Add-Ons & Services

DatagramSocket send example in slides not working

Please post support and help requests here.

DatagramSocket send example in slides not working

Postby fatslug » 25 Sep 2013, 14:44

Hi,

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.data(), 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.data(), 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!
fatslug
 
Posts: 1
Joined: 25 Sep 2013, 14:30

Return to Support

Who is online

Users browsing this forum: No registered users and 3 guests