Hey Jules,
I am new to socket programming and trying to transfer data between two applications through UDP Socket.
I have two applications, say Application A and Application B.
Application A sends data in a specified protocol format through UDP at a particular Port ID and Application B receives the data from the same Port ID. I am using DatagramSocket class in both the applications.Everything works fine till it comes to reading the data packets from Application A, Application B is not able to bind with the port to which Application A is connected to.
Application A
unsigned char us8Data;
DatagramSocket* _pDatagramSocket;
ApplicationA::ApplicationA()
{
_pDatagramSocket = new DatagramSocket( const int localPortNumber );
us8Data = 1;
}
bool ApplicationA::statusOfConnectToPort()
{
if ( _pDatagramSocket->connect( const String& remoteHostname,const int remotePortNumber ) == true )
{
startThread( 1 );
return true;
}
else
{
return false;
}
}
void ApplicationA::run( )
{
while( ! threadShouldExit() )
{
_pDataGramWriteSocket->write( ( void* ) &us8Data , 1 );
if( us8Data < 255 )
{
us8Data += us8Data ;
}
else
{
us8Data = 1;
}
}
}
Application B
DatagramSocket* _pDatagramSocket;
ApplicationB::ApplicationB()
{
_pDatagramSocket = new DatagramSocket( const int localPortNumber );
}
bool ApplicationB::statusOfBindToPort()
{
if( _pDatagramSocket->bindToPort( const int localPortNumber ) == true )
{
startThread( 1 );
return true;
}
else
{
return false;
}
}
void ApplicationB::run( )
{
while( ! threadShouldExit() )
{
unsigned char us8DestBuffer;
int iReadyForReading = _pDatagramSocket->waitUntilReady( false , 1000 );
int iMaxBytesRead = _pDatagramSocket->read( ( unsigned char* ) &us8DestBuffer , 1 , true );
}
}
I wish if you could help me here.
Regards