Qt Forum

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

    Unsolved QSslSocket and QTcpSocket ... how to know if the connection is incorrect

    General and Desktop
    qsslsocket qtcpsocket
    3
    3
    631
    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.
    • healermagnus
      healermagnus last edited by

      I have a TCP client and server, and either can be in SSL mode or not, depending on use case. It took me a while to get the two to talk to each other in SSL mode, but that seems to be working now.

      What's confusing is that if one of the sides is not set to SSL mode, it doesn't seem to fail via disconnect. Either I'm missing a signal listener, or I don't actually have SSL mode working.

      It would seem that if either side is set to SSL and the other is not, either a disconnect should happen, or a signal is sent that I can create a handler for. The side that is set to SSL should not like the data from the non-SSL side during handshake, and something should happen.

      I admit, I'm not sending anything over the line yet, and maybe that is the moment that a disconnect happens?

      Any ideas what I'm missing?

      Pablo J. Rogina kshegunov 2 Replies Last reply Reply Quote 0
      • Pablo J. Rogina
        Pablo J. Rogina @healermagnus last edited by

        @healermagnus it would be great if you share your code as how you're using QTcpSocket or QSslSocket.

        For the later, I guess it's mandatory that you connect to the sslErrors signal

        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

        1 Reply Last reply Reply Quote 3
        • kshegunov
          kshegunov Moderators @healermagnus last edited by

          @healermagnus said in QSslSocket and QTcpSocket ... how to know if the connection is incorrect:

          Any ideas what I'm missing?

          You want a delayed handshake. Ideologically it goes like this:
          You create the QSslSocket object, but operate it as a QTcpSocket. The server and client exchange TCP messages (as per your liking) to try and negotiate whether they should stay in plain TCP or in SSL mode. When the connection is decided to be used over SSL the client calls startClientEncryption, while the server socket calls startServerEncryption to begin the actual SSL handshake. Connecting the TCP error and sslErrors() signals is a must.

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply Reply Quote 1
          • First post
            Last post