1
votes

I know how to connect a client to a server, world-wide!

check this link if you want to have a quick code to workout: http://cs.lmu.edu/~ray/notes/javanetexamples/

My question is "how can I connect two clients without the server?"

The server might be there to listen to clients, but once they connected, I want the server out of the deal and then clients can talk directly.

My server is in U.S., client A is in Europe and client B is in Asia. Clients are regular users and they just run the app and contact with other clients - it is a similar concept like team-viewer with the inter-continental peer-to-peer connection.

Again, please notice that I don't want to send anything to the server and I don't want it to be the dealer between clients. It will keep the server to always listen to new connections and prevents it from being busy delivering data between clients.

Please help me on this. Thanks

2

2 Answers

1
votes

I think that your problem will be that clients (assuming that they are any typical machine on the net) do not have well known IP addresses.

For two clients to talk, one of them will effectively have to become a server. However, things like NAT and firewalls prevent a typical machine from just opening a listening socket that is available to any other machine on the internet.

Your problem is a little like the 'active' mode of the old FTP protocol, where the server connected back to the client. This mode is difficult to use in the modern world because the servers idea of the IP address of the client is likely to be the IP address of the NAT gateway of the client's private network, and the clients idea of its IP address will be a private network IP address.

-1
votes

I found this http://www.lenholgate.com/blog/2005/11/windows-tcpip-server-performance.html doing some experiments.

If that is the case, then keeping the connections will not harm me for <3k active connections.

however, what I found in my local tests is that the worst part of client/server is the amount of time it needs to process the requests.

Although I am using threading, but we all know that threading is a fake thing to allow all part of the program run simultaneously. It is the bottleneck of the process and I have to optimize the algorithm for that part.