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. QTcpServer and QTcpSocker

QTcpServer and QTcpSocker

Scheduled Pinned Locked Moved General and Desktop
qtcpserverqtcpsocket
4 Posts 1 Posters 1.3k 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.
  • S Offline
    S Offline
    stvokr
    wrote on 4 Sept 2015, 07:54 last edited by
    #1

    Hi all,

    I have a client server application, with two tcpsockets on each side. My problem is notification problem when the server disconnect its socket.

    Disconnection Part 1: When the client socket disconnects from the server, I get a stateChanged signal of the server socket. That works well.

    void SocketServer::onStateChanged( QAbstractSocket::SocketState state )
    {
        switch( state )
        {
            case QAbstractSocket::UnconnectedState:
                if( m_socket )
                {
                    qDebug( "Socket disconnected" );
                }
                break;
    
            default:
                break;
    }
    

    Disconnection part 2: After a timeout of 5 minutes, the server will close its socket due to timeout (don't ask why...). I use a similar function as above, but I don't receive a stateChanged signal.

    Does anybody know why?

    regards
    Oliver

    1 Reply Last reply
    0
    • S Offline
      S Offline
      stvokr
      wrote on 4 Sept 2015, 09:02 last edited by
      #2

      For a better understanding, I told the server to close the connection after that timeout.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        stvokr
        wrote on 4 Sept 2015, 09:26 last edited by
        #3

        Ok, additional information:
        My client is a QThread. It works when I used the client unthreaded, but not as threaded.

        Any ideas?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          stvokr
          wrote on 4 Sept 2015, 10:41 last edited by
          #4

          I found the solution:
          The socket is setup within a thread and it's waiting / blocked by QWaitCondition until a message is send. When a message is send, the thread wakes up, the socket sends the message and waits until readyRead or timeout is triggered. That's working, but after that the thread is going to wait again and the socket is blocked again, so this is why the disconnect signal didn't get through.

          Now I replaced the QWaitCondition by waitForDisconnect() and so the socket is not blocked anymore by the wait condition, and the disconnect signal gets through.

          I think this is solved.

          1 Reply Last reply
          0

          2/4

          4 Sept 2015, 09:02

          • Login

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