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. QTCP client at same time of Qtopcua client
QtWS25 Last Chance

QTCP client at same time of Qtopcua client

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 585 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.
  • gfxxG Offline
    gfxxG Offline
    gfxx
    wrote on last edited by
    #1

    Hi ata all,

    I try to run qtcpclient at same time of qtopcua client .... it have different ip adress obviusly and different range ... but seem if run qtcp client qtopcua disconnect .... where if qtcp client not run qtopcua client works like a charms ....
    how can separate 2 socket task is same app?

    bkt

    jsulmJ 1 Reply Last reply
    0
    • gfxxG gfxx

      Hi ata all,

      I try to run qtcpclient at same time of qtopcua client .... it have different ip adress obviusly and different range ... but seem if run qtcp client qtopcua disconnect .... where if qtcp client not run qtopcua client works like a charms ....
      how can separate 2 socket task is same app?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @gfxx Please show your code

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

      gfxxG 1 Reply Last reply
      0
      • jsulmJ jsulm

        @gfxx Please show your code

        gfxxG Offline
        gfxxG Offline
        gfxx
        wrote on last edited by gfxx
        #3

        @jsulm I'm embarrassed you are answering me a similar question .... from what I understand qtopcua uses sockets so I simplified by asking the same question where I wonder why starting 2 socket clients on the same app gives disconnection problems ....

        in any case qtopcua alone works fine (whthout call tcpSocket start func) .... tcpSocket alone works fine .... there is something about abstractSocket that makes the two clients interact during connections ....

        qtopcua is connected with server opcua siemens .... so all work great ....
        tcpSocket1 try to connect to "qt fortune server example" as debug stage ..... and have disconnection or disconnect qtopcua client.

        
        MainWindow::MainWindow(const QString &initialUrl, QWidget *parent) : QMainWindow(parent)
          , ui(new Ui::MainWindow)
          , mOpcUaModel(new OpcUaModel(this))
          , mOpcUaProvider(new QOpcUaProvider(this))
        {
            ui->setupUi(this);
            ui->host->setText(initialUrl);
            mainWindowGlobal = this;
        
        
            updateUiState();
        
            ui->opcUaPlugin->addItems(QOpcUaProvider::availableBackends());
            ui->treeView->setModel(mOpcUaModel);
            ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
        
            if (ui->opcUaPlugin->count() == 0) {
                ui->opcUaPlugin->setDisabled(true);
                ui->connectButton->setDisabled(true);
                QMessageBox::critical(this, tr("No OPCUA plugins available"), tr("The list of available OPCUA plugins is empty. No connection possible."));
            }
        
            connect(ui->findServersButton, &QPushButton::clicked, this, &MainWindow::findServers);
            connect(ui->host, &QLineEdit::returnPressed, this->ui->findServersButton,
                    [this]() { this->ui->findServersButton->animateClick(); });
            connect(ui->getEndpointsButton, &QPushButton::clicked, this, &MainWindow::getEndpoints);
            connect(ui->connectButton, &QPushButton::clicked, this, &MainWindow::connectToServer);
            oldMessageHandler = qInstallMessageHandler(&messageHandler);
        
            setupPkiConfiguration();
        
        
            m_identity = m_pkiConfig.applicationIdentity();
            
            .........
            
            /******************** all works so I inser only create client ***********************/
            
            void MainWindow::createClient()
        {
            if (mOpcUaClient == nullptr) {
                mOpcUaClient = mOpcUaProvider->createClient("open62541");
                if (!mOpcUaClient) {
                    const QString message(tr("Connecting to the given sever failed. See the log for details."));
                    log(message, QString(), Qt::red);
                    QMessageBox::critical(this, tr("Failed to connect to server"), message);
                    return;
                }
        
                connect(mOpcUaClient, &QOpcUaClient::connectError, this, &MainWindow::showErrorDialog);
                mOpcUaClient->setApplicationIdentity(m_identity);
                mOpcUaClient->setPkiConfiguration(m_pkiConfig);
        
                if (mOpcUaClient->supportedUserTokenTypes().contains(QOpcUaUserTokenPolicy::TokenType::Certificate)) {
                    QOpcUaAuthenticationInformation authInfo;
                    authInfo.setCertificateAuthentication();
                    mOpcUaClient->setAuthenticationInformation(authInfo);
                }
        
                connect(mOpcUaClient, &QOpcUaClient::connected, this, &MainWindow::clientConnected);
                connect(mOpcUaClient, &QOpcUaClient::disconnected, this, &MainWindow::clientDisconnected);
                connect(mOpcUaClient, &QOpcUaClient::errorChanged, this, &MainWindow::clientError);
                connect(mOpcUaClient, &QOpcUaClient::stateChanged, this, &MainWindow::clientState);
                connect(mOpcUaClient, &QOpcUaClient::endpointsRequestFinished, this, &MainWindow::getEndpointsComplete);
                connect(mOpcUaClient, &QOpcUaClient::findServersFinished, this, &MainWindow::findServersComplete);
            }
        }
        
        
        void MainWindow::startSokconnection1(){   /* a timer singleshot call startSokconnection1 after 4 sec of tcpSocket was in connected state */
        
            tcpSocket1 = new QTcpSocket();
            in1.setDevice(tcpSocket1);
            in1.setVersion(QDataStream::Qt_5_15);
        
           tcpSocket1->connectToHost("19x.16x.51.xxx", xx051); //(ipHost, ipPort.toShort()); //ipPort.toShort());
            
           if (tcpSocket1->waitForConnected()){
                        qDebug("Connected -1-"); 
           }
            connect(tcpSocket1,&QAbstractSocket::disconnected,[]()->void{qDebug("Disconnected -1-");});
        
            connect(tcpSocket1, &QIODevice::readyRead, this, &MainWindow::readFortune1);
            connect(tcpSocket1, &QAbstractSocket::stateChanged, this, &MainWindow::sokState1);
            connect(tcpSocket1, &QAbstractSocket::errorOccurred, this, &MainWindow::displayError1);
        
        }
        

        bkt

        Christian EhrlicherC 1 Reply Last reply
        0
        • gfxxG gfxx

          @jsulm I'm embarrassed you are answering me a similar question .... from what I understand qtopcua uses sockets so I simplified by asking the same question where I wonder why starting 2 socket clients on the same app gives disconnection problems ....

          in any case qtopcua alone works fine (whthout call tcpSocket start func) .... tcpSocket alone works fine .... there is something about abstractSocket that makes the two clients interact during connections ....

          qtopcua is connected with server opcua siemens .... so all work great ....
          tcpSocket1 try to connect to "qt fortune server example" as debug stage ..... and have disconnection or disconnect qtopcua client.

          
          MainWindow::MainWindow(const QString &initialUrl, QWidget *parent) : QMainWindow(parent)
            , ui(new Ui::MainWindow)
            , mOpcUaModel(new OpcUaModel(this))
            , mOpcUaProvider(new QOpcUaProvider(this))
          {
              ui->setupUi(this);
              ui->host->setText(initialUrl);
              mainWindowGlobal = this;
          
          
              updateUiState();
          
              ui->opcUaPlugin->addItems(QOpcUaProvider::availableBackends());
              ui->treeView->setModel(mOpcUaModel);
              ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
          
              if (ui->opcUaPlugin->count() == 0) {
                  ui->opcUaPlugin->setDisabled(true);
                  ui->connectButton->setDisabled(true);
                  QMessageBox::critical(this, tr("No OPCUA plugins available"), tr("The list of available OPCUA plugins is empty. No connection possible."));
              }
          
              connect(ui->findServersButton, &QPushButton::clicked, this, &MainWindow::findServers);
              connect(ui->host, &QLineEdit::returnPressed, this->ui->findServersButton,
                      [this]() { this->ui->findServersButton->animateClick(); });
              connect(ui->getEndpointsButton, &QPushButton::clicked, this, &MainWindow::getEndpoints);
              connect(ui->connectButton, &QPushButton::clicked, this, &MainWindow::connectToServer);
              oldMessageHandler = qInstallMessageHandler(&messageHandler);
          
              setupPkiConfiguration();
          
          
              m_identity = m_pkiConfig.applicationIdentity();
              
              .........
              
              /******************** all works so I inser only create client ***********************/
              
              void MainWindow::createClient()
          {
              if (mOpcUaClient == nullptr) {
                  mOpcUaClient = mOpcUaProvider->createClient("open62541");
                  if (!mOpcUaClient) {
                      const QString message(tr("Connecting to the given sever failed. See the log for details."));
                      log(message, QString(), Qt::red);
                      QMessageBox::critical(this, tr("Failed to connect to server"), message);
                      return;
                  }
          
                  connect(mOpcUaClient, &QOpcUaClient::connectError, this, &MainWindow::showErrorDialog);
                  mOpcUaClient->setApplicationIdentity(m_identity);
                  mOpcUaClient->setPkiConfiguration(m_pkiConfig);
          
                  if (mOpcUaClient->supportedUserTokenTypes().contains(QOpcUaUserTokenPolicy::TokenType::Certificate)) {
                      QOpcUaAuthenticationInformation authInfo;
                      authInfo.setCertificateAuthentication();
                      mOpcUaClient->setAuthenticationInformation(authInfo);
                  }
          
                  connect(mOpcUaClient, &QOpcUaClient::connected, this, &MainWindow::clientConnected);
                  connect(mOpcUaClient, &QOpcUaClient::disconnected, this, &MainWindow::clientDisconnected);
                  connect(mOpcUaClient, &QOpcUaClient::errorChanged, this, &MainWindow::clientError);
                  connect(mOpcUaClient, &QOpcUaClient::stateChanged, this, &MainWindow::clientState);
                  connect(mOpcUaClient, &QOpcUaClient::endpointsRequestFinished, this, &MainWindow::getEndpointsComplete);
                  connect(mOpcUaClient, &QOpcUaClient::findServersFinished, this, &MainWindow::findServersComplete);
              }
          }
          
          
          void MainWindow::startSokconnection1(){   /* a timer singleshot call startSokconnection1 after 4 sec of tcpSocket was in connected state */
          
              tcpSocket1 = new QTcpSocket();
              in1.setDevice(tcpSocket1);
              in1.setVersion(QDataStream::Qt_5_15);
          
             tcpSocket1->connectToHost("19x.16x.51.xxx", xx051); //(ipHost, ipPort.toShort()); //ipPort.toShort());
              
             if (tcpSocket1->waitForConnected()){
                          qDebug("Connected -1-"); 
             }
              connect(tcpSocket1,&QAbstractSocket::disconnected,[]()->void{qDebug("Disconnected -1-");});
          
              connect(tcpSocket1, &QIODevice::readyRead, this, &MainWindow::readFortune1);
              connect(tcpSocket1, &QAbstractSocket::stateChanged, this, &MainWindow::sokState1);
              connect(tcpSocket1, &QAbstractSocket::errorOccurred, this, &MainWindow::displayError1);
          
          }
          
          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @gfxx said in QTCP client at same time of Qtopcua client:

          about abstractSocket that makes the two clients interact during connections

          For sure two separate instances don't interact with each other except you wrote it. As written in the other thread - provide a minimal, compilable example to reproduce the issue.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          gfxxG 1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            @gfxx said in QTCP client at same time of Qtopcua client:

            about abstractSocket that makes the two clients interact during connections

            For sure two separate instances don't interact with each other except you wrote it. As written in the other thread - provide a minimal, compilable example to reproduce the issue.

            gfxxG Offline
            gfxxG Offline
            gfxx
            wrote on last edited by gfxx
            #5

            @Christian-Ehrlicher said in QTCP client at same time of Qtopcua client:

            For sure two separate instances don't interact with each other except you wrote it. As written in the other thread - provide a minimal, compilable example to reproduce the issue.

            ok ... just a moment .... I try to not start qtopcua client .... but problem remain .... tcpSocket go to unconnected state after connection .... my terminal messages:

            Connected!  /* referred to lambda function for debug messages*/
             TCPSocket connection state:  CLOSING /* these is referred to qabstractsocket::state function */
             TCPSocket connection state:  UNCONNECTED
            Disconnected  /* referred to lambda function for debug messages*/
            

            bkt

            1 Reply Last reply
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Again - without some real code which we can compile here locally you can say anything but we can't help. You for sure doing something wrong or the server disconnects your connection.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              gfxxG 1 Reply Last reply
              1
              • Christian EhrlicherC Christian Ehrlicher

                Again - without some real code which we can compile here locally you can say anything but we can't help. You for sure doing something wrong or the server disconnects your connection.

                gfxxG Offline
                gfxxG Offline
                gfxx
                wrote on last edited by gfxx
                #7

                @ all

                if (tcpSocket->waitForConnected()){
                    qDebug("Connected!");
                    firstb = false;
                }
                

                because no msec time into waitForConnected macro .... abstractSocket switch immediately on unconnected state .... old part of my app containing a relais to call immediately reconnection id unconnected stare is reached .... so I see all that problem ....

                Insert 3000ms and see al wheels ....

                Probabily qtopcua disconnect because too many reconnection request .... actually we try from 1 hout whitout any issue

                thanks to all for support.

                bkt

                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