Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to initiate direct connection between clients connected to a server

Suppose that I have a server and the clients are connected to the server. The server is accessible through a public ip.

I would like to "forward" the connection so that the clients would be directly connected to each other withouth the server in the middle.

I do not know if this is possible at all and I myself couldn't find a way to do it.

Other assumptions:

  • neither client has a public IP, both clients are behind a NAT
  • there can be more connections initiated if necessary

I am looking for a strictly software solution, without the need to reconfigure router, open ports, etc. etc.

The reason I would like to achieve this is to reduce the load on server. Once a two clients are associated together there is no real need (except technical one) to continue using the server as a, sort of, proxy. Direct client connection would also reduce the latency of the connection.

like image 242
Dariusz Avatar asked May 29 '13 10:05

Dariusz


People also ask

How would you establish a connection between client and server?

To establish a connection from a client to a server, the client has to know the network listening name of the server and in some cases, also the location of the server in the network. For ODBC connections, a default connect string can be defined with the client-side Com. Connect configuration parameter.

What is a direct connection to server?

"Direct connect" is a service allowing you to set up a dedicated network connection from your premises or another service provider to Servers.com. A private connection can increase bandwidth throughput and provide a more consistent network experience than Internet-based connections.

How do I connect two computers as client and server?

Connect all of the computers to be networked to a router. Attach one end of an Ethernet cable to a computer's network card and the other end to the proper connection on the router. Do this for each computer and the server to be networked. Power on the router and all of the computers.

How do I create a connection between two servers?

You can create connections between servers across a local area network (LAN) or wide area network (WAN), by using a pass-through server (a server that acts as an intermediary server between a client and its destination), or over the Internet.


2 Answers

Take a look at http://en.wikipedia.org/wiki/UDP_hole_punching. If neither machine has a public IP, and you can't open ports, and you don't want all data to pass through the server, this is probably the only other potential option. If this wouldn't work for you, you're likely stuck with all data going through the server. If you can set up port forwarding, that would make for a better solution, then just use the server to exchange IP and port information (as it exists at the time the connection is established).

like image 128
user1676075 Avatar answered Sep 28 '22 13:09

user1676075


A short answer is: it is not possible.

One of the main problems is that router do not know where to redirect the request from the server (or other client). Just a case : You have a router which has multiple devices(computer, cell phone...) behind it. It gets a request and do not know, who wants to get the request.

There is a workaround for that but it is not reliable (Does not work always.) Some Companies use it if it is possible, but they have always an alternative to that (like communication over server) if it fails. It is called nat punching. More details here: http://en.wikipedia.org/wiki/TCP_hole_punching

I do not know for which reason do you need. If you need it for client server connection you can use something like long polling, call back....

Otherwise you need to set the router, or take the route over the server.

like image 23
Mert Avatar answered Sep 28 '22 13:09

Mert