Create peer-to-peer connections using an intermediate server

I want to connect two clients (via TCP / IP sockets). Clients can discover each other using an intermediate server. When clients discover each other, there should be no server involvement.

I studied this and found many people offering JXTA . But I would like to create the protocol myself from scratch (because in the future I may have to implement the same with WebSockets (when my client is a browser)). Currently, my clients may be desktop applications or mobile applications.

My questions:

  • How will clients discover each other on the server? If the server sends the global IP address of the clients to each other, will this information be sufficient to create a peer-to-peer connection? What if clients are on the same LAN and the server is on another wide area network?

  • The client has a dynamic IP address. Can their IP change suddenly, even if it has an active socket?

  • Is a peer-to-peer connection reliable for transmitting non-continuous data (for example, in a chat application)?

[NOTE: by peer-to-peer, I mean establishing a TCP / IP socket connection to the client server (using Java), making one of the clients a temporary socket server]

Thanks in advance.

+4
source share
1 answer

1) When clients connect to the server, they will need to notify the server of the port number that they will open for incoming connections from other clients. The server will know the IP address of the client. Then the server will need to inform / send this data to the other party / client. The actual location of the customers does not matter. If two clients are on the same network, network routers will find them and shorten their communication paths.

2) The dynamic IP address CANNOT change during an active connection - if it disconnects and both clients will have to re-initiate the connection through the server in 1)

3) Yes

+5
source

All Articles