Overview
Features
Download
Documentation
Community
Add-Ons & Services

Need help with simple DatagramSocket communication

Please post support and help requests here.

Need help with simple DatagramSocket communication

Postby SamBushman » 17 May 2012, 03:00

I have just started using the Poco library. I am having issues getting two computers to successfully communicate using Poco's DatagramSocket objects. Specifically, the receiveBytes function does not seem to return (despite running Wireshark and seeing that the UDP packets I am sending ARE arriving at the destination machine). I assume I am omitting something simple and this is all due to a dumb mistake on my part. I have compiled Poco 1.4.3p1 on Windows 7 using Visual Studio Express 2010. Below are code snippets showing how I am trying to use Poco. Any advise would be appreciated.

*Sending*
Code: Select all
#include "Poco\Net\DatagramSocket.h"
#include "Serializer.h" //A library used for serializing data

int main()
{
   Poco::Net::SocketAddress remoteAddr("192.168.1.140", 5678); //The IP address of the remote (receiving) machine
   Poco::Net::DatagramSocket mSock; //We make our socket (its not connected currently)
   mSock.connect(remoteAddr); //Sends/Receives are restricted to the inputted IPAddress and port
   unsigned char float_bytes[4];
   FloatToBin(1234.5678, float_bytes); //Serializing the float and storing it in float_bytes
   mSock.sendBytes((void*)float_bytes, 4); //Bytes AWAY!
   return 0;
}


*Receiving (where I am having issues)*
Code: Select all
#include "Poco\Net\DatagramSocket.h"
#include "Poco\Net\SocketAddress.h"
#include "Serializer.h"
#include <iostream>

int main()
{
   Poco::Net::SocketAddress remoteAddr("192.168.1.116", 5678); //The IP address of the remote (sending) machine
   Poco::Net::DatagramSocket mSock; //We make our socket (its not connected currently)
   mSock.connect(remoteAddr); //Sends/Receives are restricted to the inputted IPAddress and port
   //Now lets try to get some datas
   std::cout << "Waiting for float" << std::endl;
   unsigned char float_bytes[4];
   mSock.receiveBytes((void*)float_bytes, 4); //The code is stuck here waiting for a packet. It never returns...
   //Finally, lets convert it to a float and print to the screen
   float net_float;
   BinToFloat(float_bytes, &net_float); //Converting the binary data to a float and storing it in net_float
   std::cout << net_float << std::endl;
   system("PAUSE");
   return 0;
}


Thanks for your time,
Sam Bushman
SamBushman
 
Posts: 1
Joined: 17 May 2012, 02:50

Return to Support

Who is online

Users browsing this forum: No registered users and 1 guest

cron