这是出现主要错误的代码
与我的本地 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)