Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Extending networking/socket programming functionality of a qml project
Forum Updated to NodeBB v4.3 + New Features

Extending networking/socket programming functionality of a qml project

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
92 Posts 5 Posters 17.2k Views 2 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.
  • S Offline
    S Offline
    SGaist
    Lifetime Qt Champion
    wrote on 18 May 2022, 20:00 last edited by
    #61

    I know that you are talking about the "@". As I wrote, it's about authentication. There are several ways to do it.

    As for the client side, did you connect the error signals of your socket ?
    Does your server really answer on port 443 ?

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    Q 1 Reply Last reply 18 May 2022, 20:45
    1
    • S SGaist
      18 May 2022, 20:00

      I know that you are talking about the "@". As I wrote, it's about authentication. There are several ways to do it.

      As for the client side, did you connect the error signals of your socket ?
      Does your server really answer on port 443 ?

      Q Offline
      Q Offline
      qcoderpro
      wrote on 18 May 2022, 20:45 last edited by qcoderpro
      #62

      @SGaist

      I get this message for this error:

       case QAbstractSocket::ConnectionRefusedError:
              qInfo() << "The connection was refused by the peer. "
                         "Make sure the server is running, "
                         "and check that the host name and port "
                         "settings are correct.";
      

      As for the port number, they say in Sending an Update in their website: If updating over HTTPS, our system listens on Port 443 It is not necessary to open any incoming ports for updating.

      Of course both apps are running on the same machine.

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qcoderpro
        wrote on 18 May 2022, 21:16 last edited by qcoderpro
        #63

        Sorry, there was a problem with my connection. Now that I runt the two apps (on my Windows machine), they both run successfully (with no errors) but messages won't be sent/received. That is, whatever I write and click on the Send button, nothing appears on the other side! :(

        When sending messages on the server app, the error below appears on the Application Output window:
        "QIODevice::write (QTcpSocket): device not open"

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 18 May 2022, 21:46 last edited by
          #64

          You are mixing noip API server and yours. They are not the same and the port you use for your application is unrelated to the one you use to update your account.

          As for your socket issue, I do not see any error checking done in your code so you do not even know whether your connection was successful.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          Q 1 Reply Last reply 18 May 2022, 22:02
          0
          • S SGaist
            18 May 2022, 21:46

            You are mixing noip API server and yours. They are not the same and the port you use for your application is unrelated to the one you use to update your account.

            As for your socket issue, I do not see any error checking done in your code so you do not even know whether your connection was successful.

            Q Offline
            Q Offline
            qcoderpro
            wrote on 18 May 2022, 22:02 last edited by
            #65

            @SGaist

            You are mixing noip API server and yours. They are not the same and the port you use for your application is unrelated to the one you use to update your account.

            Sounds reasonable. So what port number should I use for my client app to be able to connect to the server app, please? The sever sends its IP by updating the record, but how about a port? How to find a port for the connection?

            J 1 Reply Last reply 19 May 2022, 05:42
            0
            • Q qcoderpro
              18 May 2022, 22:02

              @SGaist

              You are mixing noip API server and yours. They are not the same and the port you use for your application is unrelated to the one you use to update your account.

              Sounds reasonable. So what port number should I use for my client app to be able to connect to the server app, please? The sever sends its IP by updating the record, but how about a port? How to find a port for the connection?

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 19 May 2022, 05:42 last edited by
              #66

              @qcoderpro said in Extending networking/socket programming functionality of a qml project:

              So what port number should I use for my client app to be able to connect to the server app, please?

              The port your server is listening for connections.
              It is your server, so you should know what server you use.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              Q 1 Reply Last reply 19 May 2022, 13:33
              0
              • J jsulm
                19 May 2022, 05:42

                @qcoderpro said in Extending networking/socket programming functionality of a qml project:

                So what port number should I use for my client app to be able to connect to the server app, please?

                The port your server is listening for connections.
                It is your server, so you should know what server you use.

                Q Offline
                Q Offline
                qcoderpro
                wrote on 19 May 2022, 13:33 last edited by
                #67

                @jsulm
                The server may be run by someone in another country, so how the client should know the port number!? :|
                Furthermore, you said: port number can be fixed (like 8080 for HTTP).

                For the connection both IP and port are needed, As far as I'm concerned. No-ip works out the problem with IP. But how about the port number? :(

                J 1 Reply Last reply 19 May 2022, 13:57
                0
                • Q qcoderpro
                  19 May 2022, 13:33

                  @jsulm
                  The server may be run by someone in another country, so how the client should know the port number!? :|
                  Furthermore, you said: port number can be fixed (like 8080 for HTTP).

                  For the connection both IP and port are needed, As far as I'm concerned. No-ip works out the problem with IP. But how about the port number? :(

                  J Offline
                  J Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 19 May 2022, 13:57 last edited by
                  #68

                  @qcoderpro Question: do you have to use a fix port number or not? Port can be fixed like it is for many protocols.

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  Q 1 Reply Last reply 19 May 2022, 15:45
                  0
                  • J jsulm
                    19 May 2022, 13:57

                    @qcoderpro Question: do you have to use a fix port number or not? Port can be fixed like it is for many protocols.

                    Q Offline
                    Q Offline
                    qcoderpro
                    wrote on 19 May 2022, 15:45 last edited by qcoderpro
                    #69

                    @jsulm
                    I don't know since I'm new to networking. Actually I chose Qt to learn socket programming. When running the apps on the same machine, the client needs both IP and port to connect to the server. The server publishes both, say, this for the port: QString::number(tcpServer->serverPort()), and since I can see them, I enter IP and port in client's fields to connect to server.
                    Now that the apps are going to work remotely, for example, each running by a person in a different location (not on the same machine), the IP problem is going to be fixed using noip. But the port problem remains. So I assume there're two ways to work it out, 1- use a fixed port or 2- use any port the server offers but this way we need to somehow deliver that number to client to give it the ability to establish the connection.
                    Now you choose what to choose please.

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 19 May 2022, 19:42 last edited by
                      #70

                      That's your application so that decision is yours.

                      As you were already explained, peer to peer communication has different constraints than the use of a central server.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      Q 1 Reply Last reply 19 May 2022, 21:43
                      0
                      • S SGaist
                        19 May 2022, 19:42

                        That's your application so that decision is yours.

                        As you were already explained, peer to peer communication has different constraints than the use of a central server.

                        Q Offline
                        Q Offline
                        qcoderpro
                        wrote on 19 May 2022, 21:43 last edited by
                        #71

                        @SGaist
                        Since I've not been dealt with projects like that, I'm seeking the easiest way. An easy free service like No-ip. I wish it could solve the issue with the port as well. :|
                        What do you suggest, please?

                        J 1 Reply Last reply 20 May 2022, 05:10
                        0
                        • Q qcoderpro
                          19 May 2022, 21:43

                          @SGaist
                          Since I've not been dealt with projects like that, I'm seeking the easiest way. An easy free service like No-ip. I wish it could solve the issue with the port as well. :|
                          What do you suggest, please?

                          J Offline
                          J Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on 20 May 2022, 05:10 last edited by
                          #72

                          @qcoderpro said in Extending networking/socket programming functionality of a qml project:

                          What do you suggest, please?

                          I suggest to use a fixed port number...

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          Q 1 Reply Last reply 20 May 2022, 21:46
                          1
                          • J jsulm
                            20 May 2022, 05:10

                            @qcoderpro said in Extending networking/socket programming functionality of a qml project:

                            What do you suggest, please?

                            I suggest to use a fixed port number...

                            Q Offline
                            Q Offline
                            qcoderpro
                            wrote on 20 May 2022, 21:46 last edited by
                            #73

                            @jsulm
                            Good. Could you also guide me how to do that? I mean if there's any reference or Docs page to help me learn how to do that I will be appreciative.

                            1 Reply Last reply
                            0
                            • S Offline
                              S Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on 21 May 2022, 19:18 last edited by
                              #74

                              https://en.m.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers

                              Interested in AI ? www.idiap.ch
                              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                              Q 1 Reply Last reply 30 May 2022, 12:24
                              1
                              • S SGaist
                                21 May 2022, 19:18

                                https://en.m.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers

                                Q Offline
                                Q Offline
                                qcoderpro
                                wrote on 30 May 2022, 12:24 last edited by qcoderpro
                                #75

                                @SGaist
                                Sorry for the delay. I was very busy. If you think it's better, I'm going to create a new thread for the problem.

                                I checked the page for the ports numbers and tested a couple of them which are related to messaging based on TCP.

                                My server.cpp has:

                                Server::Server(QObject *parent)
                                    : QObject{parent}
                                    , tcpSocket(new QTcpSocket(this))
                                    , tcpServer(new QTcpServer(this))
                                {
                                    initServer();
                                }
                                
                                QString Server::initServer() {
                                
                                    tcpServer = new QTcpServer(this);
                                    if(!tcpServer->listen())
                                        return "Server Unable to start the server: " +
                                                tcpServer->errorString();
                                
                                    connect(tcpServer, &QTcpServer::newConnection, this, &Server::onNewConnection);
                                
                                    QByteArray auth = "myEmail@gmail.com:myPass";
                                    QByteArray authHeaderData = "Basic " + auth.toBase64();
                                
                                    QUrl requestUrl("https://dynupdate.no-ip.com/nic/update");
                                    requestUrl.setQuery("hostname=coderdev.ddns.net");
                                
                                    QNetworkRequest request(requestUrl);
                                    request.setRawHeader("Authorization", authHeaderData);
                                
                                    QNetworkAccessManager* qnam = new QNetworkAccessManager(this);
                                    QNetworkReply * reply = qnam->get(request);
                                
                                    if(reply->error())
                                        qInfo() << "ERROR!: " + reply->errorString();
                                    else
                                        qInfo() << "Reply got back with no error!";
                                }
                                
                                void Server::onNewConnection() {
                                
                                    qInfo() << "New connection arrived!";
                                
                                    tcpSocket = tcpServer->nextPendingConnection();
                                    connect(tcpSocket, &QAbstractSocket::errorOccurred, this, &Server::displayError);
                                    inOut.setDevice(tcpSocket);
                                    inOut.setVersion(QDataStream::QDataStream::Qt_5_10);
                                    connect(tcpSocket, &QAbstractSocket::readyRead, this, &Server::writeMessage);
                                }
                                ...
                                

                                First ran this app and got the message: Reply got back with no error!

                                client.cpp contains:

                                Client::Client(QObject *parent)
                                    : QObject{parent}
                                    , tcpSocket(new QTcpSocket(this))
                                {
                                    inOut.setDevice(tcpSocket);
                                    inOut.setVersion(QDataStream::Qt_5_10);
                                    connect(tcpSocket, &QAbstractSocket::readyRead, this, &Client::writeMessage);
                                    connect(tcpSocket, &QAbstractSocket::errorOccurred, this, &Client::displayError);
                                
                                    QHostInfo info = QHostInfo::fromName("coderdev.ddns.net");
                                    sendAddress(info.addresses().front(), 4662);
                                
                                    /*   18	Message Send Protocol[19][20]
                                         157	Assigned  KNET/VM Command/Message Protocol
                                         218	Message posting protocol (MPP)
                                         993	Internet Message Access Protocol over TLS/SSL (IMAPS)[11]
                                         2123	GTP control messages (GTP-C)
                                         2152	GTP user data messages (GTP-U)
                                         2775	Short Message Peer-to-Peer (SMPP)[citation need
                                         4662	OrbitNet Message Service
                                    */
                                }
                                
                                void Client::sendAddress(QHostAddress ip, unsigned int port)
                                {
                                    tcpSocket->abort();
                                    tcpSocket->connectToHost(ip, port);
                                }
                                ...
                                

                                After running the server (and hoping that the record on noip has been updated correctly), ran the client and tested all ports above!
                                Yet no new connection nor an error from the displayError slot.
                                But Qt Creator gives the error: Cannot retrieve debugging output. for all of the ports!

                                Where is the problem, please? :(

                                1 Reply Last reply
                                0
                                • S Offline
                                  S Offline
                                  SGaist
                                  Lifetime Qt Champion
                                  wrote on 30 May 2022, 17:53 last edited by
                                  #76

                                  You do not set the port on the server.

                                  Also, you create the QTcpServer object twice. Not an issue per se but it does not make any sense.

                                  Interested in AI ? www.idiap.ch
                                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  Q 1 Reply Last reply 30 May 2022, 19:09
                                  1
                                  • S SGaist
                                    30 May 2022, 17:53

                                    You do not set the port on the server.

                                    Also, you create the QTcpServer object twice. Not an issue per se but it does not make any sense.

                                    Q Offline
                                    Q Offline
                                    qcoderpro
                                    wrote on 30 May 2022, 19:09 last edited by
                                    #77

                                    @SGaist
                                    Yeah thank you.

                                    In the previous version (when the two app run on the same machine) we don't have port setting. How to set the port on the server, please?

                                    1 Reply Last reply
                                    0
                                    • S Offline
                                      S Offline
                                      SGaist
                                      Lifetime Qt Champion
                                      wrote on 30 May 2022, 19:25 last edited by
                                      #78

                                      It's all in the documentation of the listen method.

                                      Interested in AI ? www.idiap.ch
                                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                      Q 1 Reply Last reply 30 May 2022, 19:45
                                      1
                                      • S SGaist
                                        30 May 2022, 19:25

                                        It's all in the documentation of the listen method.

                                        Q Offline
                                        Q Offline
                                        qcoderpro
                                        wrote on 30 May 2022, 19:45 last edited by qcoderpro
                                        #79

                                        I firstly run the server and get: Reply got back with no error!, for this code:

                                        void Server::initServer() {
                                        
                                            if(!tcpServer->listen(QHostAddress::Any, 4662))
                                                qInfo() << "Server Unable to start the server: " +
                                                        tcpServer->errorString();
                                        
                                            connect(tcpServer, &QTcpServer::newConnection, this, &Server::onNewConnection);
                                        
                                            QByteArray auth = "myEmail@gmail.com:myPass";
                                            QByteArray authHeaderData = "Basic " + auth.toBase64();
                                        
                                            QUrl requestUrl("https://dynupdate.no-ip.com/nic/update");
                                            requestUrl.setQuery("hostname=coderdev.ddns.net");
                                        
                                            QNetworkRequest request(requestUrl);
                                            request.setRawHeader("Authorization", authHeaderData);
                                        
                                            QNetworkAccessManager* qnam = new QNetworkAccessManager(this);
                                            QNetworkReply * reply = qnam->get(request);
                                        
                                            if(reply->error())
                                                qInfo() << "ERROR!: " + reply->errorString();
                                            else
                                                qInfo() << "Reply got back with no error!";
                                        }
                                        

                                        Then when running the client and texting, nothing is shown on the other side and get the error: QIODevice::write (QTcpSocket): device not open, on the server. :|

                                        Q 1 Reply Last reply 30 May 2022, 20:12
                                        0
                                        • Q qcoderpro
                                          30 May 2022, 19:45

                                          I firstly run the server and get: Reply got back with no error!, for this code:

                                          void Server::initServer() {
                                          
                                              if(!tcpServer->listen(QHostAddress::Any, 4662))
                                                  qInfo() << "Server Unable to start the server: " +
                                                          tcpServer->errorString();
                                          
                                              connect(tcpServer, &QTcpServer::newConnection, this, &Server::onNewConnection);
                                          
                                              QByteArray auth = "myEmail@gmail.com:myPass";
                                              QByteArray authHeaderData = "Basic " + auth.toBase64();
                                          
                                              QUrl requestUrl("https://dynupdate.no-ip.com/nic/update");
                                              requestUrl.setQuery("hostname=coderdev.ddns.net");
                                          
                                              QNetworkRequest request(requestUrl);
                                              request.setRawHeader("Authorization", authHeaderData);
                                          
                                              QNetworkAccessManager* qnam = new QNetworkAccessManager(this);
                                              QNetworkReply * reply = qnam->get(request);
                                          
                                              if(reply->error())
                                                  qInfo() << "ERROR!: " + reply->errorString();
                                              else
                                                  qInfo() << "Reply got back with no error!";
                                          }
                                          

                                          Then when running the client and texting, nothing is shown on the other side and get the error: QIODevice::write (QTcpSocket): device not open, on the server. :|

                                          Q Offline
                                          Q Offline
                                          qcoderpro
                                          wrote on 30 May 2022, 20:12 last edited by
                                          #80

                                          My hostname is also active.

                                          Capture.PNG

                                          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