简体   繁体   English

Python-在公共Internet协议上制作套接字服务器

[英]Python - Make socket server on Public Internet Protocol

On Python I would like to make a python server on my public IP... 在Python上,我想在我的公共IP上制作一个python服务器...

import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

s.bind(("Public IP", 80))
s.listen(5)
conn, addr = s.accept()

But once it hits the bind command 但是一旦命中bind命令

error: [Errno 10049] The requested address is not valid in its context

How would I fix this, how would I get other people around the globe to connect to my python server. 如何解决此问题,如何使全球其他人连接到我的python服务器。

You can only bind to an address that's configured on an interface on your local machine. 您只能绑定到在本地计算机上的接口上配置的地址。 Since you're using the phrase "public IP", I'm assuming that your public IP is only configured on your router, and your computer has a private address on your local network. 由于您使用的是“公共IP”一词,因此我假设您的公共IP仅在路由器上配置,并且您的计算机在本地网络上具有私有地址。

Have your program bind to the machine's local IP, or to any IP available (eg, ("", 80) ), then configure port forwarding on your router appropriately. 让您的程序绑定到计算机的本地IP或任何可用的IP(例如("", 80) ),然后在路由器上适当配置端口转发。

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

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