Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How QTcpSocket client can understand that it is in the queue? (and does not go to connected state)
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 500 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bamshad
    wrote on last edited by
    #1

    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?

    Pablo J. RoginaP 1 Reply Last reply
    0
    • B Bamshad

      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?

      Pablo J. RoginaP Offline
      Pablo J. RoginaP Offline
      Pablo J. Rogina
      wrote on last edited by
      #2

      @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.

      Upvote the answer(s) that helped you solve the issue
      Use "Topic Tools" button to mark your post as Solved
      Add screenshots via postimage.org
      Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

      B 1 Reply Last reply
      3
      • Pablo J. RoginaP Pablo J. Rogina

        @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.

        B Offline
        B Offline
        Bamshad
        wrote on last edited by
        #3

        @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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved