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. TCP Server Connection
Forum Updated to NodeBB v4.3 + New Features

TCP Server Connection

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 1.7k 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
    AlperenUnal
    wrote on last edited by AlperenUnal
    #1

    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();
    

    }

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

      @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?

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

      A 1 Reply Last reply
      1
      • A AlperenUnal

        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();
        

        }

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

        @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?

        A 1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          @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?

          A Offline
          A Offline
          AlperenUnal
          wrote on last edited by
          #4

          @Christian-Ehrlicher

          I couldn't figure out what should I wrote for connection with the nodeMCU IP adress :(

          Christian EhrlicherC 1 Reply Last reply
          0
          • JonBJ JonB

            @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?

            A Offline
            A Offline
            AlperenUnal
            wrote on last edited by
            #5

            @JonB

            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?

            1 Reply Last reply
            0
            • A AlperenUnal

              @Christian-Ehrlicher

              I couldn't figure out what should I wrote for connection with the nodeMCU IP adress :(

              Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @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."

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

              A 1 Reply Last reply
              0
              • Christian EhrlicherC Christian Ehrlicher

                @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."

                A Offline
                A Offline
                AlperenUnal
                wrote on last edited by
                #7

                @Christian-Ehrlicher
                Okey, I will try it, thanks for the help :)

                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