如何解决为什么端口转发在我的python客户端到python服务器上不起作用?
因此,要开始端口转发,我将UPnPc与命令upnpc -a 10.0.0.21 10000 3333 TCP
一起使用(10.0.0.21 =内部IP)(10000 =内部端口)(3333 =外部端口)(TCP =方法),并获得成功消息表示已成功启动,并且可以通过给定的外部IP和端口进行连接。这是我的服务器代码:
sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
sock.bind((internal_IP,internal_Port))
sock.listen(1)
#the code then afterwards waits for connections and prints them
如果我随后使用客户端,我在python中编写了使用外部IP和外部端口进行连接的操作,则连接失败,表示连接被拒绝。但是,如果我使用内部IP和内部端口,那么一切都会正常进行。
这是我的客户代码:
sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
sock.connect((IP,port))
#if the IP is the internal one (and the port is too) then it works just fine
#if the IP and port are the external ones set up through port forwarding it says that connection failed
那么,为什么端口转发不适用于我的代码?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。