一些实用信息:操作系统:Windows 10(安装了 WSL2)IDE:Emacs
我正在使用 python 套接字库的项目中工作。
我创建了一个类来组织服务器进程,在该服务器内部我有方法“requestConnection”,当我调用该方法时,它给了我一个错误“Errno 22 [invalid argument]”。
这是错误:
Traceback (most recent call last):
File "SocketChat.py", line 4, in <module>
servidor.requestConnection()
File "/mnt/c/Users/Mauro/Development/Projects/SocketChat/server.py", line 16, in requestConnection
self.con = self.server_socket.accept()
File "/usr/lib/python3.8/socket.py", line 292, in accept
fd, addr = self._accept()
OSError: [Errno 22] Invalid argument
这是主要代码:
from server import Server, Chat
servidor = Server('127.0.0.1', '5000')
servidor.requestConnection()
chat = Chat(servidor.receiveMsg())
这是课程:
import socket
class Server:
def __init__(self, host, port):
self.host = host
self.port = port
self.addr = (host, port)
self.server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
def shutDown(self):
self.server_socket.close()
def requestConnection(self):
self.con = self.server_socket.accept()
def receiveMsg(self):
receive = self.con.recv(1024)
return str(receive)
class Chat:
def __init__(msg):
self.msg = msg
pass
def newMsg(self):
print(f"new message: {self.msg.decode()}")
pass
如果你知道如何解决这个问题,请给我答案