I have written a client and a server-side code to set a P2P type system with a server as a middleman to distribute a file to N clients.
I am getting this error OSError: [WinError 10022] An invalid argument was supplied in this chunk of my code on the server side
try:
for i in l:
print(i)
x = random.randint(0,N-1)
print(x,"Index")
serverSocketTCPRequest = serverSocketTCPList[x]
serverSocketTCPRequest.settimeout(2)
serverSocketTCPRequest.connect((i[0],i[1]))
serverSocketTCPRequest.send("SEND".encode())
serverSocketTCPRequest.send(str(chunkID).encode())
data = serverSocketTCPRequest.recv(1024)
serverSocketTCPRequest.close()
b = False
return data
except Exception as ex:
print(traceback.format_exc())
time.sleep(1)
# print(l)
pass
I am getting the following error:
Traceback (most recent call last):
File "d:\IITD\5th Sem\COL334\Assignment 2\server.py", line 149, in getChunks
serverSocketTCPRequest.connect((i[0],i[1]))
OSError: [WinError 10022] An invalid argument was supplied
Traceback (most recent call last):
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "d:\IITD\5th Sem\COL334\Assignment 2\server.py", line 198, in sendChunkRequest
checkMessage, serverAddress = serverSocketUDPRequest.recvfrom(1024)
socket. Timeout: timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "d:\IITD\5th Sem\COL334\Assignment 2\server.py", line 149, in getChunks
serverSocketTCPRequest.connect((i[0],i[1]))
OSError: [WinError 10022] An invalid argument was supplied
My client side code for the same is
def handleTCP(client:Client):
global N
while(True):
try:
# print(clientList.index(client), client.clientSocketTCPRequest.getsockname())
client.clientSocketTCPRequest.listen(2*N)
client.clientSocketTCPRequest.settimeout(2)
connectionSocket, addr = client.clientSocketTCPRequest.accept()
print("Connected")
message = connectionSocket.recv(1024).decode()
if message.decode() == "SEND":
i = connectionSocket.recv(1024).decode()
connectionSocket.send(client.dict[int(i)])
connectionSocket.close()
elif message.decode() == "GET":
i = connectionSocket.recv(1024).decode()
client.dict[int(i)] = connectionSocket.recv(1024)
connectionSocket.close()
except Exception as ex:
template = "An exception of type {0} occurred. Arguments:\n{1!r}"
m = template.format(type(ex).__name__, ex.args)
print(m,client.clientSocketTCPRequest.getsockname())
# print(traceback.format_exc())
continue
I can't think of a reason this is occurring. The client side shows just a timeout error on each of the N ports.
I have attached the entire client and server side codes and the file I'm trying to send.