Remote Connection Progam Like Teamviewer - tcp

The Standard TCPServer and TCPClient don't work on my machine for some reason, but Teamviewer manages to make a connection between two machines, and I would guess that the actual remote desktop session isn't going through their servers as it would probably be quite heavy.
Could someone explain to be how this is possible, because I've tried every TCP server/client code I could find and it still cannot connect recieve information from the outside world.

TeamViewer uses a technique called UDP Hole Punching.
This allows to connect two nat'd peers without make data pass through a server.

Related

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.
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).
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.
You can do two things one is hole punching http://en.wikipedia.org/wiki/TCP_hole_punching
so this will allow you to respond to your client who are behind NAT (you can configure your client to send their private ip and port number used by NAT to reply to them).
Other thing you can do is to make a peer-to-peer network as done by skype and make one of the client as relay network and keep track of active relay's and update them periodically. (see http://en.wikipedia.org/wiki/Skype_protocol )
So now your server has to just act as proxy and as an admin which kind of manage all connection but least amount of info pass through it.
I hope this help.
Some home routers support upnp and can be instructed to open a certain port and forward it to a certain client on the LAN.
You can use upnpc on GNU/Linux to open ports on the router. It also has a library to do it from C code (but it's not very well documented).
However this method might not work on all home devices, so in that case see the other answers.

How do IM applications manage to let users transfer files between differrent LANs

I am working on a program related to network, and there's a situation that the client has to connect to a server which is inside a LAN.
As I know, when establishing a TCP connection, the port the server is listening on has to be accessable to the client. If the server is inside a LAN, port accesses are blocked by the router. One solution I know is to use UPnP to perform a port mapping on the router. However, in some cases, the router does not support UPnP, are there other solutions?
IM applications came up into my mind. Many IM applications have the functionality that users can send files to each other, whatever the network environment is, as long as you can access to the internet. I don't think a public server is used as a file data exchanger between the two, the connection has to be a direct one. How do they actually do to enable the client to connect to a "hidden" server?
Typically such programs try a series of steps:
A connect directly to B
B connect directly to A
A tries to connect to a firewall (uPnP) forwarded port to B
B tries to connect to a firewall (uPnP) forwarded port to A
A and B both connect to a central server and exchange data through that
The last step is obviously the least preferred because the provider has to have sufficient resources to manage all simultaneous transfers. Rate-limiting is common.
Since IM has central management anyway, it's not too difficult to coordinate all this.
If uPnP or an open port can't be done at one end or the other then the only option left would seem to be passing it via a server in the middle

Connecting to a computer remotely

I found a tutorial that shows you how to create server and client programs, and make them communicate over a network.
http://www.win32developer.com/tutorial/winsock/winsock_tutorial_1.shtm
I can make a client program connect to, for example, 192.168.0.4 on my local network, and I can make it connect to 74.125.225.96. But what if I wanted to make it communicate with 192.168.0.4 on the network of 74.125.225.96, instead of just the default server on 74.125.225.96? I'm having a difficult time finding the answer with Google.
Is there even a way to do this? If not, then how are Gnutella and Bittorrent, able to connect computers directly together to share files?
To do what you are asking, 74.125.225.96 would have to be assigned to a router that is configured to forward inbound connections on the target server port to the machine that is running 192.168.0.4.
BitTorrent and other file sharing apps use various techniques, like NAT traversal, hole punching, etc to get connections through routers and firewalls. For example, if one party is behind a router/firewall and the other party is not, then the two apps first try to connect to each other in one direction, and if that fails then they reverse roles - client becomes server and server becomes client - and they try again. If that still fails, they could then connect to a middleman server that both parties have access to, and let it delegate the connections.

Passive connection protocols or tunnels, how do they work

I was wondering how tools like teamviewer work. I'm not using the words server and client because I am not quite sure who is who. So I will talk about local and remote.
I have a tool installed on a remote machine behind firewalls and NAT, so only port 80 is okay for outbound connections. Now the local machine wants to connect to the remote machine. The only way I can image connection to work, is if the remote polls the local machine to check if it wants to connect, and then the remote establishes a connection to the local machine.
Teamviewer uses the same mechanism only with one entity in the middle, so the remote doesn't have to know the local in advance? So the remote always polls the entity in the internet?
Is that the way this kind of connection works? It seems quite a wast, always having to poll the local or some dealer-webserver. Especially if the connection has to work quickly, the polls must happen every second?
Am I missing something?
If someone is to scared to answer, a simple yes or no does the trick :-)
The hole punshing approach, so it's a yes.

how does teamviewer find my computer even if my comp. behind of the firewall and firewall isn't configured?

Did you use teamviewer? (comic question i know... Who doesn't use it?)
Do you have any idea how does teamviewer make connection even if i am behind the router, firewall, switch and my local firewall..?
I'm trying to imagine a connection that is between remote machinge and my computer. Remote machine is sending the packets (and its header (for instance, destination IP, message body)) to me but it only knows my id number(which is given by my local teamviewer application).
And this packets are reaching to my computer even if there is a juniper firewall (and also my windows firewall).
What kind a message body is recieving by computer? (of course it is not like xml, text, html, excel :)
Do you have any idea?
PS. Please share your knowledge like you are explaining to beginner level user.
The software is communicating with a central server, and has made an outbound connection. When you start TeamViewer, it will try to make a direct connection, but if both directions fail that (ie. firewall or NATting at both places), then it will fall back on communicating through a server.
This is basically the same approach most online games use. Changes at one end is sent to a central server, and is then relayed back to other connected computers.

Resources