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. QSslSocket in non-http protocol
QtWS25 Last Chance

QSslSocket in non-http protocol

Scheduled Pinned Locked Moved Unsolved General and Desktop
qsslsocket
7 Posts 2 Posters 348 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.
  • A Offline
    A Offline
    artwaw
    wrote on 29 Jul 2024, 10:34 last edited by artwaw
    #1

    Good morning,
    I am trying - for the fun of it - connect and parse a page using the Gemini protocol. And I ran into an issue I can't solve, I keep running in circles. I blame my poor knowledge of socket programming.

    The problem:
    I can connect to the host and get the content but only when using domain global address, i.e. somepage.org
    Whenever I try to get particular document (think: webpage, just extension is .gmi instead of .html) I get an error from the server.

    The specification of a request is simple:

    request = absolute-URI CRLF
    

    My code:

    oid GeminiProtocol::fetchPage(const QString &uri) {
        if (uri.isEmpty()) { qDebug() << "uri empty"; return; }
        QString query = uri;
        QString _uri = uri;
        QStringList parts = query.remove("gemini://").split('/',Qt::SkipEmptyParts);
        if (socket.state()==QSslSocket::ConnectedState||socket.state()==QSslSocket::ConnectingState) {
            socket.close();
        }
        _uri.append(QChar::CarriageReturn).append(QChar::LineFeed);
        socket.connectToHostEncrypted(parts.at(0),_port);
        socket.write(QByteArray(_uri.toUtf8()));
    }
    

    The question:
    is this boilerplate code above more or less ok (I have slots connected to signals in case of an error etc) or have I missed something?

    For more information please re-read.

    Kind Regards,
    Artur

    A 1 Reply Last reply 29 Jul 2024, 11:36
    0
    • A artwaw
      29 Jul 2024, 10:34

      Good morning,
      I am trying - for the fun of it - connect and parse a page using the Gemini protocol. And I ran into an issue I can't solve, I keep running in circles. I blame my poor knowledge of socket programming.

      The problem:
      I can connect to the host and get the content but only when using domain global address, i.e. somepage.org
      Whenever I try to get particular document (think: webpage, just extension is .gmi instead of .html) I get an error from the server.

      The specification of a request is simple:

      request = absolute-URI CRLF
      

      My code:

      oid GeminiProtocol::fetchPage(const QString &uri) {
          if (uri.isEmpty()) { qDebug() << "uri empty"; return; }
          QString query = uri;
          QString _uri = uri;
          QStringList parts = query.remove("gemini://").split('/',Qt::SkipEmptyParts);
          if (socket.state()==QSslSocket::ConnectedState||socket.state()==QSslSocket::ConnectingState) {
              socket.close();
          }
          _uri.append(QChar::CarriageReturn).append(QChar::LineFeed);
          socket.connectToHostEncrypted(parts.at(0),_port);
          socket.write(QByteArray(_uri.toUtf8()));
      }
      

      The question:
      is this boilerplate code above more or less ok (I have slots connected to signals in case of an error etc) or have I missed something?

      A Offline
      A Offline
      Axel Spoerl
      Moderators
      wrote on 29 Jul 2024, 11:36 last edited by
      #2

      @artwaw said in QSslSocket in non-http protocol:

      I get an error from the server.

      Which error do you get?
      Do you get it only with gemini, or also with a normal http request?

      Software Engineer
      The Qt Company, Oslo

      1 Reply Last reply
      0
      • A Offline
        A Offline
        artwaw
        wrote on 29 Jul 2024, 12:15 last edited by
        #3

        51 which usually means 404 in http. I could understand that on one resource, but I get it constantly when asking for any.

        I shall post http test result as soon as I rewrite part of it to work with http...

        For more information please re-read.

        Kind Regards,
        Artur

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Axel Spoerl
          Moderators
          wrote on 29 Jul 2024, 12:24 last edited by
          #4

          In that case, you may want to debug all the credentials used to connect (_uri, parts, _port). Maybe something goes wrong building those. That would explain the 51 coming up all the time.

          Software Engineer
          The Qt Company, Oslo

          A 1 Reply Last reply 29 Jul 2024, 12:43
          1
          • A Axel Spoerl
            29 Jul 2024, 12:24

            In that case, you may want to debug all the credentials used to connect (_uri, parts, _port). Maybe something goes wrong building those. That would explain the 51 coming up all the time.

            A Offline
            A Offline
            artwaw
            wrote on 29 Jul 2024, 12:43 last edited by
            #5

            @Axel-Spoerl I did that and found nothing out of order. So I posted here, in hope there is something obvious about sockets that I missed - I don't use them very often and never for http related stuff (qnam is good enough).

            I shall also download some other gemini client and verify the existence of resources I am trying to reach, it dawned on me that some of links might be out of date. I shall post my findings here and close the thread in due time.

            Many thanks for the advice!

            For more information please re-read.

            Kind Regards,
            Artur

            1 Reply Last reply
            0
            • A Offline
              A Offline
              Axel Spoerl
              Moderators
              wrote on 29 Jul 2024, 12:48 last edited by
              #6

              I can feel the pain. Trying the same requests with another toolset is always a good idea!
              Getting curious about what caused the issue.

              Software Engineer
              The Qt Company, Oslo

              A 1 Reply Last reply 30 Jul 2024, 17:43
              0
              • A Axel Spoerl
                29 Jul 2024, 12:48

                I can feel the pain. Trying the same requests with another toolset is always a good idea!
                Getting curious about what caused the issue.

                A Offline
                A Offline
                artwaw
                wrote on 30 Jul 2024, 17:43 last edited by
                #7

                @Axel-Spoerl small updates:

                1. I tried different Gemini browser, namely Sputnik (written in Swift) - works barely better than my prototype but it does work and I could verify the links - they do work, so the problem is within my code somewhere.
                2. there is a Qt5 multi browser named Kristall, written with Qt5 and long not updated at all. Porting it to Qt6 should not be much of a problem (some outdated classes, like QRegExp but not much of it), porting it to macOS is a bit more complex so I'll not attempt unless bored. BUT. They also use QSslSocket so now I'll have a read through their code and see where did I go wrong.

                More updates once I do the read.

                For more information please re-read.

                Kind Regards,
                Artur

                1 Reply Last reply
                0

                1/7

                29 Jul 2024, 10:34

                • Login

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