PDA

View Full Version : UDP on the same machine??



bryang
7th March 2011, 23:16
Is it possible to UDP between two separate applications on the same PC?

I have a need to test an application that I wrote that is meant to communicate via unicast UDP to a special device. I don't have regular access to this device, so I would like to write a "simulator" that would run on the same computer. My application would talk UDP to that simulator, which in turn would provide responses.

Is this possible?

In fact, I have tried using the code snippets shown below with no success. I don't see any data being sent or received. I'm wondering if I don't have the IP/ports set correctly.

I would very much appreciate any assistance or advice.

Bryan


Application A (my application):
IP_mine = QHostAddress("Localhost");
IP_target = QHostAddress("Localhost");
port_mine = 51200;
port_target = 51201;
bool success = m_udpSocket.bind(IP_mine,port_mine);
.
.
.
m_udpSocket.writeDatagram((char*)&buffer,sizeof(buffer), IP_target, port_send);



Application B (my simulator):
IP_mine = QHostAddress("Localhost");
IP_target = QHostAddress("Localhost");
port_mine = 51201;
port_target = 51200;
bool success = m_udpSocket.bind(IP_mine,port_mine);
.
.
.
m_udpSocket.writeDatagram((char*)&buffer,sizeof(buffer), IP_target, port_send);

schnitzel
8th March 2011, 00:33
take a look at broadcast sender/receiver example, I think that is exactly what you need.