简体   繁体   English

远程连接不起作用。 无法使用 python 套接字连接到服务器

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

[WinError 10061] and [WinError 10060]. [WinError 10061] 和 [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 PS:客户端收到错误而不是服务器

welcome to SO.欢迎来到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.确保 IP 不是您的本地网络 IP 而是路由器的 IP。 check on wahtismyip .检查wahtismyip Use that as the ip.将其用作 ip。 Note that the ip will change every so often.请注意,ip 会经常更改。
  • 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.您需要告诉您的路由器(或您的朋友,如果服务器在他的网络中)将到达端口 33000 的数据包中继到服务器。 This is different from device to device, try googling "Port forwarding ".这因设备而异,请尝试使用谷歌搜索“端口转发”。

Hopefully this resolves your issues.希望这可以解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM