How QTcpSocket client can understand that it is in the queue? (and does not go to connected state)



  • I work on a server and client project with Qt. I want to print the connection status for the users. For this propose I use state() like:

    socketState = mySocket.state();

    if (socketState == 3) {
    Print("we have connected");
    }
    However, it does not work when the server queues new connections. To make it clear, my client state is 3 even if the server has paused accepting new connections:

    //server side:
    myServer->pauseAccepting();

    //client side:
    connectToHost()
    socketState = mySocket.state();
    Now the socketState is 3 instead of 0 or a special number for queue state.

    To sum it up, I want to know how to inform the client that it is in the queue? Is there anything like state() that has a return value for queue state?



  • @Bamshad although you didn't mentioned in your post, I assume you're using both QTcpSocket for the client and QTcpServer for the server. Given that said, you may want to check QTcpServer documentation for an explanation as why your sockets are in connected state.

    Clients may still able to connect after the server has reached its maximum number of pending connections (i.e., QTcpSocket can still emit the connected() signal). QTcpServer will stop accepting the new connections, but the operating system may still keep them in queue.



  • @Pablo-J.-Rogina Yes they are still connected although the server has reached the maximum number of clients. I used write() (in the server) and read() (in the client) so if the read() return value is 0 it means that it (client) is in the queue. This method works fine as long as the first client is still connected. If it disconnected (I do not know why) in the server side write() does not work properly and therefore it can not send anything and the new client think it is in the queue.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.