Reputation: 33
Some util informations: OS: Windows 10 (with WSL2 installed) IDE: Emacs
I'm working in a project using the python socket library.
I made a class to organize the server processes, inside that server I have the method "requestConnection", when I call the method it gives me an error "Errno 22 [invalid argument]".
Here's the error:
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
Here's the main code:
from server import Server, Chat
servidor = Server('127.0.0.1', '5000')
servidor.requestConnection()
chat = Chat(servidor.receiveMsg())
Here's the classes:
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
If you know how to solve this problem, please give-me the answer
Upvotes: 0
Views: 721
Reputation: 775
Try to pass the port number as integer, not string:
from server import Server, Chat
servidor = Server('127.0.0.1', 5000)
Upvotes: 2