通过我的公共 IP 通过 TCP 连接到我自己 [英] Connecting to myself through my public IP through TCP
问题描述
我正在尝试使用我的公共 IP 连接到我自己的机器.如果我使用 127.0.0.1
连接成功,但使用公共 IP 会导致以下错误:"ConnectionRefusedError: [WinError 10061] 由于目标机器主动拒绝,无法建立连接它"
.
I'm trying to connect to my own machine using my public IP. If I use 127.0.0.1
the connection is successful, but using the public IP results in the following error: "ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it"
.
根据MSDN,该错误可能是因为没有运行服务器应用程序;但是,在运行client.py"之前,我确实先运行了server.py"脚本.我应该怎么做才能解决这个问题?
According to MSDN, the error might appear because no server application is running; however, I did run the 'server.py' script first, before running 'client.py. What should I do to fix this?
server.py
from socket import *
sock = socket(AF_INET, SOCK_STREAM)
sock.bind(('127.0.0.1', 8888))
sock.listen(10)
conn, _ = sock.accept()
client.py
from socket import *
sock = socket(AF_INET, SOCK_STREAM)
sock.connect((MY_PUBLIC_IP, 8888))
推荐答案
很可能是您的防火墙或路由器,如果您打开了.尝试将防火墙配置为允许访问该端口,如果您使用的是路由器,请进行端口转发.
It's most likely your firewall or router if you have on. Try configuring your firewall to allow access on that port, and doing port forwarding if you're using a router.
这篇关于通过我的公共 IP 通过 TCP 连接到我自己的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!