Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    QTcpServer and QTcpSocker

    General and Desktop
    qtcpserver qtcpsocket
    1
    4
    1204
    Loading More Posts
    • 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
      stvokr last edited by

      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 Reply Quote 0
      • S
        stvokr last edited by

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

        1 Reply Last reply Reply Quote 0
        • S
          stvokr last edited by

          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 Reply Quote 0
          • S
            stvokr last edited by

            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 Reply Quote 0
            • First post
              Last post