Poniat
Poniat

Reputation: 11

Remote connection not working. Couldn't connect to server with python socket

[WinError 10061] and [WinError 10060]. These are the errors im getting when i send a client app to my friend. Remotely it just doesn't work. Locally it works fine. Can i get a full explanation step by step please cause i couldn't find any soulution and i'm getting mad.

SERVER:

import socket as s

HOST = 'ppp.ppp.p.ppp'
PORT = 33000

server_socket = s.socket(s.AF_INET, s.SOCK_STREAM)
server_socket.bind((HOST, PORT))
server_socket.listen()

while True:
    client_socket, address = server_socket.accept()
    print(f'Connected {address}')

CLIENT:

import socket as s

HOST = 'ppp.ppp.p.ppp'
PORT = 33000

client_socket = s.socket(s.AF_INET, s.SOCK_STREAM)
client_socket.connect((HOST, PORT)) # here is error

PS: CLIENT GETS ERRORS NOT SERVER

Upvotes: 1

Views: 861

Answers (1)

Jakob Tinhofer
Jakob Tinhofer

Reputation: 377

welcome to SO. You and your friend are probably not on the same network. Therefore, when sending a connection request, your router (or your friends) does not know to relay the packet to the correct device in it's network. There are multiple things you need to do:

  • Make sure that the IP is not your local network IP but rather the IP of your router. check on wahtismyip. Use that as the ip. Note that the ip will change every so often.
  • Then, the difficult part. You need to tell your router (or your friends if the server is in his network) to relay the packets arriving at port 33000 to the server. This is different from device to device, try googling "Port forwarding ".

Hopefully this resolves your issues.

Upvotes: 1

Related Questions