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. A connect function slow down the connection between QTCPserver and client
QtWS25 Last Chance

A connect function slow down the connection between QTCPserver and client

Scheduled Pinned Locked Moved Solved General and Desktop
qtcpserverqtcpsocket
4 Posts 2 Posters 1.1k 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.
  • DoohamD Offline
    DoohamD Offline
    Dooham
    wrote on last edited by
    #1

    Hello,
    I am developing a code for a connection between a server and a client. My goal, is to read the messages from a device connected to my computer by a serial port (this will be the server) and sending the messages to other program that decode them. I have no troubles with read the serial port and decode the messages. But I have to implement other function: sending a message to the device from the client, I can encode the message in a QByteArray, and sending to the device. However, to make this possible I use a connect function between a signal readyRead and a function to write the message in the serial port. When I implement this function, the connection between the client and the server takes a few seconds more that without the connect.

    This is the connect section:

     socket = server->nextPendingConnection();
          connect(socket,SIGNAL(disconnected()),this,SLOT(clientDisconnected()));
          connect(socket,SIGNAL(readyRead()), this, SLOT(on_readyRead()));
          qDebug()<<"Hola Nuevo Cliente";
    

    An this is the function on_readyRead()

    void MyServer::on_readyRead()
    {
        msgSend="";
        socket->waitForReadyRead(3000);
        msgSend=socket->readAll();
    
            qDebug()<<msgSend;
    mipuerto->writeMsg(msgSend);
    
    
    
    }
    

    The write function itself doesn't have any troubles, and I can send the message to the device, and it understand the message and execute the orders. However, it takes a few second to establish the connection between the server and the client. And when I send the message from the client to the server, it also takes a few seconds.
    Thanks you for your help.

    DoohamD 1 Reply Last reply
    0
    • DoohamD Dooham

      Hello,
      I am developing a code for a connection between a server and a client. My goal, is to read the messages from a device connected to my computer by a serial port (this will be the server) and sending the messages to other program that decode them. I have no troubles with read the serial port and decode the messages. But I have to implement other function: sending a message to the device from the client, I can encode the message in a QByteArray, and sending to the device. However, to make this possible I use a connect function between a signal readyRead and a function to write the message in the serial port. When I implement this function, the connection between the client and the server takes a few seconds more that without the connect.

      This is the connect section:

       socket = server->nextPendingConnection();
            connect(socket,SIGNAL(disconnected()),this,SLOT(clientDisconnected()));
            connect(socket,SIGNAL(readyRead()), this, SLOT(on_readyRead()));
            qDebug()<<"Hola Nuevo Cliente";
      

      An this is the function on_readyRead()

      void MyServer::on_readyRead()
      {
          msgSend="";
          socket->waitForReadyRead(3000);
          msgSend=socket->readAll();
      
              qDebug()<<msgSend;
      mipuerto->writeMsg(msgSend);
      
      
      
      }
      

      The write function itself doesn't have any troubles, and I can send the message to the device, and it understand the message and execute the orders. However, it takes a few second to establish the connection between the server and the client. And when I send the message from the client to the server, it also takes a few seconds.
      Thanks you for your help.

      DoohamD Offline
      DoohamD Offline
      Dooham
      wrote on last edited by
      #2

      @Dooham
      Ok, I have seen that the delay is due to waitforReadyRead(x), the wait a time and freeze the program during this time. I have changed the value from 3000 to 100 and now, the program works better, but I am not really conviced about this solution.

      jsulmJ 1 Reply Last reply
      0
      • DoohamD Dooham

        @Dooham
        Ok, I have seen that the delay is due to waitforReadyRead(x), the wait a time and freeze the program during this time. I have changed the value from 3000 to 100 and now, the program works better, but I am not really conviced about this solution.

        jsulmJ Online
        jsulmJ Online
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @Dooham Why do you have this waitForReadyRead() in on_readyRead()?
        on_readyRead() is called when readyRead() signal is emitted and that happens when there is something to read.

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

        DoohamD 1 Reply Last reply
        6
        • jsulmJ jsulm

          @Dooham Why do you have this waitForReadyRead() in on_readyRead()?
          on_readyRead() is called when readyRead() signal is emitted and that happens when there is something to read.

          DoohamD Offline
          DoohamD Offline
          Dooham
          wrote on last edited by
          #4

          @jsulm Hi, thanks for your answer and sorry for my delay, I haven't login in the forum during the weekend. You are right, I eliminated this line and I didn't get this trouble.

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved