Add-Ons & Services

DatagramSocket Question

Please post support and help requests here.
Posts: 7
Joined: 25 Feb 2009, 05:08

DatagramSocket Question

Postby Warren » 25 Feb 2009, 05:34

I want make a program to receive any UDP package sent by any sender. I do it as the instructions on the page(http://pocoproject.org/wiki/index.php/C ... ss_sockets).
I do it as the follow steps:
Poco::Net::SocketAddress addr;
Poco::Net::DatagramSocket socket;
socket.bind( addr );
please note: addr is wildcard address: no the specific host and the certain port.
char buff[1024];
memset( buff, 0, 1024 );
while( TRUE )
socket.receiveFrom( buff, sizeof( buff ), addr );
std::cout << "Receive buff from " << addr.host().toString() << ":" <<addr.port() << "[data: " << buff << "]" <<std::endl ;
Sleep( 10 );
but the socket can't receive any data. If I change addr parameters, for example, I declare the addr like this:
Poco::Net::SocketAddress addr( "", 2500 );
socket handler will work well.
If you get the answer, please note, Thanks for attention!

Posts: 1182
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: DatagramSocket Question

Postby guenter » 25 Feb 2009, 07:23

You must at least specify a port number, even if you use a wildcard IP address. You can't use a wildcard port number with sockets. Looks like the Wiki page is wrong here.

Posts: 7
Joined: 25 Feb 2009, 05:08

Re: DatagramSocket Question

Postby Warren » 25 Feb 2009, 08:05

Thanks guenter. I solve the problem following you suggestion.
I set ip is wildcard "", and the port is a valid integer numeric. It works well.

Return to “Support”

Who is online

Users browsing this forum: No registered users and 1 guest