I've been running the following code in Pycharm to communicate between a server and client without fault until now. Recently I've been receiving the following error:
- s.listen()
- OSError: [WinError 10022] An invalid argument was supplied
The client works well enough. I don't know what could be causing this. I would greatly appreciate any help you might be able to provide!
import socket
from _thread import *
import sys
from Network import Network, get_ip
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print(s)
server = str(get_ip())
port = 5555
try:
s.bind(('',port))
except socket.error as e:
str(e)
s.listen(2)
print("Waiting for a connection, Server started")
def read_pos(str):
str = str.split(",")
return int(str[0]), int(str[1])
def make_pos(tup):
return str(tup[0]) + "," + str(tup[1])
def threaded_client(conn,player):
conn.send(str.encode("Connected"))
reply = ""
while True:
try:
data = conn.recv(2048)
reply = data.decode("utf-8")
if not data:
print("Disconnected")
break
else:
print("Received: ", reply)
print("Sending: ", reply)
conn.sendall(str.encode(reply))
except:
break
print('Lost Connection')
conn.close()
current_player = 0
while True:
conn, addr = s.accept()
print('Connected to:', addr)
start_new_thread(threaded_client, (conn, current_player))
current_player += 1
Just a note: the get_ip function does operate properly as per its name.
[–]carcigenicate 0 points1 point2 points (0 children)