小编Bil*_*l B的帖子

Python 无法使用套接字绑定我的外部/公共 IP 地址,给出错误但是当使用本地 IP 地址时,错误不会显示

这是出现主要错误的代码

与我的本地 IP 的绑定将起作用:

s.bind(("192.168.1.4", port))
Run Code Online (Sandbox Code Playgroud)

与我的公共 IP 的绑定失败并出现以下错误

s.bind(("99.99.99.99", port))
Run Code Online (Sandbox Code Playgroud)

[WinError 10049] 请求的地址在其上下文中无效

以下是有关我的代码的更多上下文:


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

port = 6767

try:
    s.bind(("192.168.1.4", port))  # will work fine as local ip is used but 
                                   # when used public ip the error is thrown
except socket.error as e:
    print(str(e)+"aa")

s.listen(2)
Run Code Online (Sandbox Code Playgroud)

python sockets

3
推荐指数
1
解决办法
1861
查看次数

标签 统计

python ×1

sockets ×1