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. [Solved] How to react to closed QTcpSocket
Forum Updated to NodeBB v4.3 + New Features

[Solved] How to react to closed QTcpSocket

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.7k Views 1 Watching
  • 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.
  • C Offline
    C Offline
    curator
    wrote on last edited by
    #1

    Dear all,

    I make progess in my skills on how to communicate between sockets. Currently, I have implemented a server, that is inherited by QTcpServer. I react on the signal "new connection" after I start listening mode. Wenn new connection is called, take the nextPendingConnection Socket and store a point to it in a list of all connected sockets. Then I have a nice communication application with allows communication between different client (over the server), too.

    The problem is: Is one of the clients is quit, in my implementation the server doesnt know that. So, if the server start to communicate with this client, I get some errors, as the socket is not connected anymore. I think of two solutions, but dont know how to realize either of them

    1. (dirty)
      When the server start to send data, check is the socket is still connected. How do I do that? QTcpSocket.isOpen() does not seems to do the job, as it results in "true" when the connected socket is closed....

    2. (clean)
      Is there any signal I get catch on the server then a client is closed? Then I could simply clean up my list of "valid" clients. Any suggestions?

    kind regards,
    curator

    1 Reply Last reply
    0
    • T Offline
      T Offline
      turaz
      wrote on last edited by
      #2

      In my opinion the best way is using signal disconnected() from client's QTcpSocket.

      1 Reply Last reply
      0
      • IamSumitI Offline
        IamSumitI Offline
        IamSumit
        wrote on last edited by
        #3

        Hiii,
        use following slot for Disconnected signal at server side

        void Server::slotDisconnected()

        {

        QTcpSocket client = (QTcpSocket)sender();//it will point the client which would disconnected

        }

        hope it helps :)

        Be Cute

        1 Reply Last reply
        0
        • C Offline
          C Offline
          curator
          wrote on last edited by
          #4

          Yeah, it really solved the problem. Thanks a lot!

          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