TCP Server Connection
-
Hello everyone,
I am trying to communicate between QT Creator and nodeMCU and I want to use QT Creator as a server mission and use nodeMCU as a client. At nodeMCU, I wrote the code for client and I can communicate over Telnet but I can not communicate over QT Creator. At QT Creator, I can only communicate with my computer local host but I couldn't connect to the nodeMCU. What should I do? My nodeMCU has 192.168.1.104 IP addresses and I will communicate over the 8888 port.
My cpp code is like this for the QT Creator.
#include "myserver.h"
MyServer::MyServer(QObject *parent) : QObject(parent)
{
server =new QTcpServer(this);
connect(server,SIGNAL(newConnection()),this,SLOT(newConnection()));if(!server->listen(QHostAddress("127.0.0.1"),23)) { qDebug()<<"Server couldn't started!"; } else { qDebug()<<"Server started!"; }
}
void MyServer::newConnection()
{QTcpSocket *socket =server->nextPendingConnection(); socket->write("hello \r\n"); socket->flush(); socket->waitForBytesWritten(2000); socket->close();
}
-
@AlperenUnal said in TCP Server Connection:
QHostAddress("127.0.0.1")
You listen on 127.0.0.1 (localhost) - so how should a client be able to connect to this client at 192.168.1.104 then?
-
Hello everyone,
I am trying to communicate between QT Creator and nodeMCU and I want to use QT Creator as a server mission and use nodeMCU as a client. At nodeMCU, I wrote the code for client and I can communicate over Telnet but I can not communicate over QT Creator. At QT Creator, I can only communicate with my computer local host but I couldn't connect to the nodeMCU. What should I do? My nodeMCU has 192.168.1.104 IP addresses and I will communicate over the 8888 port.
My cpp code is like this for the QT Creator.
#include "myserver.h"
MyServer::MyServer(QObject *parent) : QObject(parent)
{
server =new QTcpServer(this);
connect(server,SIGNAL(newConnection()),this,SLOT(newConnection()));if(!server->listen(QHostAddress("127.0.0.1"),23)) { qDebug()<<"Server couldn't started!"; } else { qDebug()<<"Server started!"; }
}
void MyServer::newConnection()
{QTcpSocket *socket =server->nextPendingConnection(); socket->write("hello \r\n"); socket->flush(); socket->waitForBytesWritten(2000); socket->close();
}
@AlperenUnal
Firstly Qt Creator is just an IDE for editing/debugging programs. Qt Creator is not relevant here. What might matter is for you to state what version of Qt itself you are using?My nodeMCU has 192.168.1.104 IP addresses and I will communicate over the 8888 port.
How is that related to you using
server->listen(QHostAddress("127.0.0.1"),23)
then?At nodeMCU, I wrote the code for client and I can communicate over Telnet
Not sure what you mean about "communicate over Telnet " if your nodeMCU is a client? In any case what command do you use for telnet in case it is relevant?
-
@AlperenUnal said in TCP Server Connection:
QHostAddress("127.0.0.1")
You listen on 127.0.0.1 (localhost) - so how should a client be able to connect to this client at 192.168.1.104 then?
I couldn't figure out what should I wrote for connection with the nodeMCU IP adress :(
-
@AlperenUnal
Firstly Qt Creator is just an IDE for editing/debugging programs. Qt Creator is not relevant here. What might matter is for you to state what version of Qt itself you are using?My nodeMCU has 192.168.1.104 IP addresses and I will communicate over the 8888 port.
How is that related to you using
server->listen(QHostAddress("127.0.0.1"),23)
then?At nodeMCU, I wrote the code for client and I can communicate over Telnet
Not sure what you mean about "communicate over Telnet " if your nodeMCU is a client? In any case what command do you use for telnet in case it is relevant?
Actually, I was trying to say that from telnet screen I wrote open 127.0.0.1 23, and I could see which signal has been sent.
Actually my main goal is sending a command signal like 'E' or 'H' to the nodeMCU from QTCreator and then with reading these values from nodeMCU, I will try to blink LED. Could you please help me?
-
I couldn't figure out what should I wrote for connection with the nodeMCU IP adress :(
@AlperenUnal said in TCP Server Connection:
I couldn't figure out what should I wrote for connection with the nodeMCU IP adress :(
Then simply listen to all interfaces -> https://doc.qt.io/qt-5/qtcpserver.html#listen
"If address is QHostAddress::Any, the server will listen on all network interfaces." -
@AlperenUnal said in TCP Server Connection:
I couldn't figure out what should I wrote for connection with the nodeMCU IP adress :(
Then simply listen to all interfaces -> https://doc.qt.io/qt-5/qtcpserver.html#listen
"If address is QHostAddress::Any, the server will listen on all network interfaces."@Christian-Ehrlicher
Okey, I will try it, thanks for the help :)