Unexpected QAbstractSocket::RemoteHostClosedError

  • Hi, this is my first question on this forum :)
    I am writing a multiplayer chess game. I am writing the server side in c++ and the client side in Python (PySide2). The OS I have is windows 10.
    On the client side I have a QUdpSocket and a QWebSocket. I use the udpsocket in order to find the server automatically, rather than hardcoding its url. I write a datagram to the server which contains the client's username.
    On the server side I receive the datagram and parse the username from it. Here I have two classes. Player and Game. HichessServer is the class that runs the server. Inside processPendingDatagrams it parses the username and sends the server url inside a datagram to the client. The client receives it and connects to the server. On new connection I pick a username from username queue and create a new player. If possible I start a game from two players.
    I am sharing the code via pastebin, so that it doesn't take up much space.
    This is the server source file: https://pastebin.com/gPLWF9q8,
    this is the server header file: https://pastebin.com/tdQ8VFxr.
    This is the client: https://pastebin.com/R9uLNqjL

    Now about the problem I am facing.
    When the first client connects to the server, everything is ok. But when I try to connect with the second client, I get RemoteHostClosedError right before onNewConnection slot is called and the first client disconnects. removeClient doesn't remove the first client properly in this case, probably because of the error. Here are the logs of the server side when I connect the server with these two clients: https://pastebin.com/TjXRbZgi.
    I get these logs from the first client: https://pastebin.com/vLfwQTWK.
    The only log I get from the second client is the following:
    DEBUG:root:Address: <PySide2.QtNetwork.QHostAddress("") at 0x0000026D55F5DB48>
    Which is also strange, because it must be similar to the first client's logs.

    I have already tried disabling the firewall. Nothing changed. I haven't found any bug reports or threads regarding this problem. Qt docs apparently don't talk about such a problem either. I suppose that during the process of Client2's connection to the server, the server "kicks" Client1 right before onNewConnection() slot is called.

    I apologize for such a long post. I tried my best to explain the problem clearly.
    Thanks to everyone for the help in advance 🤗

  • Update.
    I think I found the source of the problem.
    As I said, the logs of the first client and second client do not correspond. Apparently, the first client receives the datagrams, that were meant to be sent to the second client.
    All these are the first client's logs.

    // the 4 logs below are ok.
    DEBUG:root:Address: <PySide2.QtNetwork.QHostAddress("") at
    DEBUG:root:Processing datagrams...
    // the logs below should have been printed by the second client. But in fact, they are also printed by the first one. This means, that Client1 processes the datagrams that were meant to be received by Client2.
    DEBUG:root:Web client connected to server
    DEBUG:root:Processing datagrams...
    DEBUG:root:Web client connected to server

Log in to reply