Skip to content Skip to sidebar Skip to footer

How To Connect A Socket To Another Computer's Socket Through Internet

I recently have some difficulties to connect a socket to another computer's socket through Internet, an image is worth a thousand words: Computer A is running this 'listener.py' s

Solution 1:

So I would like to know how can I connect a socket to another socket through internet without changing the router configurations.

You can't. The public IP address belongs to your router. Your server isn't listening in the router, it is listening in some host behind the router. You have to open that port in your router and forward it to the host your listener is running in: whatever that means in your particular router. Otherwise the router will refuse the connection, as it doesn't have anything listening at that port.

Solution 2:

Computer B can't directly connect to computer A since it has an IP address which is not reachable from the outside. You need to set up a port forwarding rule in the 101.81.83.169 router that redirects incoming connection requests for port 50007 to IP address 192.168.0.4.

However, since you say that you are seeking a solution without changing router configurations, you need something different.

In this case, you could setup an intermediate server running on the public Internet that both computers can then connect to and serves as an intermediate tunneling platform between them. Solutions for this already exist, for example have a look at ngrok, which has Python bindings available.

Solution 3:

From the book "Computer Networking: A Top-Down Approach", there is a part which is very interesting on page 149 about how Bittorents work:

Each torrent has an infrastructure node called a tracker. When a peer joins a torrent, it registers itself with the tracker and periodically informs the tracker that it is still in the torrent. In this manner, the tracker keeps track of the peers that are participating in the torrent. A given torrent may have fewer than ten or more than a thousand peers participating at any instant of time. Alice, joins the torrent, the tracker randomly selects a subset of peers (for concreteness, say 50) from the set of participating peers, and sends the IP addresses of these 50 peers to Alice. Possessing this list of peers, Alice attempts to establish concurrent TCP connections with all the peers on this list. Let’s call all the peers with which Alice succeeds in establishing a TCP connection “neighboring peers.

image

So:

- Step 1: Alice connects to the tracker, the tracker gives to Alice the ip addresses of Bob and Mick.

- Step 2:Alice receives the ip addresses of Bob and Mick, then she can try to establish TCP/IP connections for downloading the file.

I don't remember having to set up any router configuration when I wanted to download files from Bittorent.

So what am I missing?

Post a Comment for "How To Connect A Socket To Another Computer's Socket Through Internet"