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/Socket remain connected while client dies
Forum Updated to NodeBB v4.3 + New Features

QTcpServer/Socket remain connected while client dies

Scheduled Pinned Locked Moved Solved General and Desktop
qtcpserverqtcpsocket
2 Posts 1 Posters 589 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.
  • D Offline
    D Offline
    Dariusz
    wrote on last edited by
    #1

    Hey

    This is "fun"... I have client, server test app, and when I terminate either client. The server side tcpSocket does not die/notify me of disconnection.

    When I check the socket.state() I always get ConnectedState. Even 5 min after I killed other app& socket. How can I "properly" test if the socket is really connected? Or how can I configure timeout for socket ?
    I have done this to my socket when I accepted the connection

            clientConnection = self.socketServer.nextPendingConnection()
            socket = QTcpSocket()
            socket.setSocketOption(QAbstractSocket.KeepAliveOption, 1) # apparently has to be done before connection was made on it for windows...
            socket.setSocketDescriptor(clientConnection.socketDescriptor())
            socket.setSocketOption(QAbstractSocket.KeepAliveOption, 1) # just to be sure...
            self.clientList.append(socket)
    

    That socket never tells me it dies and always has connectedState... sigh.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      Dariusz
      wrote on last edited by
      #2

      Solved.
      For some reason one of my QThread workers send a message on socket and did not post it to Socket thread... that caused it to internally "crash" without telling any1 about it and thus became "broken" internally. Once I posted it to correct thread everything started to work again... sigh! :- )

      1 Reply Last reply
      2

      • Login

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