QTCP client at same time of Qtopcua client
-
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? -
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? -
@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); }
-
@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); }
@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.
-
@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.
@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*/
-
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.
-
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.
@ 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.