0

365体育足球滚球比分I am attempting to make a simple client and server in Python. The server seems to be completely fine but the client throws the following error:

  File "C:\Users\me\Desktop\Client.py", line 6, in <module>
    connection, address = client.accept()
  File "C:\Users\me\AppData\Local\Programs\Python\Python38-32\lib\socket.py", line 292, in accept
    fd, addr = self._accept()
OSError: [WinError 10022] An invalid argument was supplied

Here is the server code:

server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind((socket.gethostname(), 8080))
server.listen(5)

while True:
    connection, address = server.accept()
    fromClient = ''

    while True:
        data = connection.recv(2048)
        if not data:
            break
        fromClient = fromClient + data
        print(fromClient)
        connection.send(str.encode('yo'))
    connection.close()
    print('client disconnected')

365体育足球滚球比分Here is the client code:

import time
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect((socket.gethostname(), 8080))
client.settimeout(3)
time.sleep(3)
#client.send(str.encode('client'))
connection, address = client.accept()
fromServer = client.recv(2048)
fromServer = fromServer.decode('utf-8')
client.close()
print(fromServer)

The server binds to the ip and port so they are OK, but the client errors out when attempting the same thing. Is there anything I can do to fix this problem?

I have also tried sleeping before the client.accept() line and this has not worked.

0

You are invoking accept method on client socket which is not set to passive mode by calling listen. Moreover, the socket is already in connected state (connect is called prior), now you cant expect your socket to listen and accept connections. But the long story short, just remove the code where you called accept in client and it runs fine.

| improve this answer | |
  • This worked! Thank you very much. – mwolfe 11 May 24 at 5:13
  • @mwolfe See how should you be accepting answers and what comments you need to post accepting-answers. Since you are new to parayshelties.community give a refresh to that link – Mohith Reddy May 24 at 5:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy365体育足球滚球比分

Not the answer you're looking for? Browse other questions tagged or ask your own question.