PDA

View Full Version : Using multiple applications on same port? (UDP) [Solved]



DrDonut
3rd June 2010, 13:17
Hi all,

Currently, I am building a set of 4 programs that have to communicate with each other using the TCP sockets. Since I don't have experience with network programming, I took the chat example (link (http://doc.qt.nokia.com/4.4/network-network-chat.html)) and pretty much build my applications on top of this.

Somehow one of the programs can only aquire data from one of the other programs, instead of all 3 other programs. To see what went wrong, I tested the example mentioned above.

When this example gets opened 4 times on the same machine, not all clients get connected to each other. When a message is sent in one client, it is not received in all other clients. (You can test this yourself to see what I mean).

This makes some sense because since the application uses UDP, and the used port is hardcoded, this means that all instances of the application use the same port (using shareAddress). When I change the port number that one of the programs uses, this program does not receive any data at all.

So my question is: Can you give me directions to a way to make all 4 programs communicate with each other using the TCP sockets?

If you need to see some code, please tell me which part and I will post it for you.

Thanks in advance!

tbscope
3rd June 2010, 14:28
Some tips:
1. Learn how peer to peer works
2. Learn about broadcasting messages
3. The most easy and ready made solution, connect 4 clients to a single server, let your server handle all the messages.

For solution 3, example:
Client 1 wants to send something to client 3, but they are not connected to each other. No problem, send a message to the server and tell the server to send it to client 3. etc. Just like a chat application would work. Every client is a client, not a server.

If you want every client to be a server too, see peer to peer. There's a bittorrent example in the Qt docs too.

DrDonut
3rd June 2010, 14:38
Thanks, I think the central server idea is the best one, I will look into that.

DrDonut