1

I get the following error:

Traceback (most recent call last):
  File "D:\Programmieren\Python\Sprach Assistent (v3)\Server\server.py", line 45, in <module>
    runserver()
  File "D:\Programmieren\Python\Sprach Assistent (v3)\Server\server.py", line 20, in runserver
    msg = client.recv(1024)
OSError: [WinError 10038] Ein Vorgang bezog sich auf ein Objekt, das kein Socket ist

and my code is:

    unverifyed_clients = []
    required_verification = "REQUIRED_VERIFICATION"
    required_verification = required_verification.encode()
    serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    serversocket.bind(('127.0.0.1', 65535))
    serversocket.listen(0)
    (client, address) = serversocket.accept()
    unverifyed_clients.append(client)
    print("A client has connected")
    while True:
        msg = client.recv(1024)
        msg.decode()
        msg = str(msg).replace("'b", "").replace("'", "")
        print("1:" + msg)
        if ("VERIFICATION:" in msg) and client in unverifyed_clients:
            msg.replace("VERIFICATION:", "")
            if msg == verification_code:
                print(msg)
                unverifyed_clients.remove(client)
                print("1a")
                time.sleep(1)
            else:
                client.close()
                print("1b")
        elif client in unverifyed_clients and not "VERIFICATION:" in msg:
            client.send(required_verification)
            time.sleep(1)
            print(3)
        elif client not in unverifyed_clients and not ("VERIFICATION:" in msg):
            print("Brain: " + msg)
            print(4)
        else:
            print(5)
Carcigenicate
  • 43,494
  • 9
  • 68
  • 117
TheMiCraft
  • 11
  • 2
  • 2
    I'm guessing `client.close()` is running, but then you're doing `client.recv` on the next iteration, even though `client` is closed. – Carcigenicate Jan 09 '21 at 15:46
  • 1
    after calling of the **client.close()**, you can no more make use of it again. in your case, after calling **client.close()**, the while loop just goes for the next iteration and calling **client.recv(1024)** and which is causing an exception. you have to make updates in code such a way that after client.close() the server waits for next client to connect. – Mahesh Anakali Jan 09 '21 at 16:14

0 Answers0