原文来源: https://stackoverflow.com/questions/48306528/python-socket-error-cannot-assign-requested-address
问:
我写了一个聊天服务器,但是我不能够将socket绑定到一个IP地址,具体代码如下:
import sys
import os
import socket
HOST = "194.118.168.131"
SOCKET_LIST = []
RECV_BUFFER = 4096
PORT = 9009
def chat_server():
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server_socket.bind((HOST, PORT))
server_socket.listen(10)
...
我得到以下错误
Traceback (most recent call last):
File "server.py", line 83, in <module>
sys.exit(chat_server())
File "server.py", line 20, in chat_serv