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. questions about qtcpserver and socket in Loopback Example
Forum Updated to NodeBB v4.3 + New Features

questions about qtcpserver and socket in Loopback Example

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

    Loopback Example tell me how to use qtcpsever and qtcpsocket. but i have a question in this example .

    1. in start function:
     while (!tcpServer.isListening() && !tcpServer.listen()) {
            QMessageBox::StandardButton ret = QMessageBox::critical(this,
                                            tr("Loopback"),
                                            tr("Unable to start the test: %1.")
                                            .arg(tcpServer.errorString()),
                                            QMessageBox::Retry
                                            | QMessageBox::Cancel);
            if (ret == QMessageBox::Cancel)
                return;
        }
    

    this while function doesn't block the program ? can just write like this ?

    tcpServer.listen() ;
    tcpServer.isListening();
    
    1. in acceptConnection function :
     tcpServerConnection = tcpServer.nextPendingConnection();
        connect(tcpServerConnection, SIGNAL(readyRead()),
                this, SLOT(updateServerProgress()));
        connect(tcpServerConnection, SIGNAL(error(QAbstractSocket::SocketError)),
                this, SLOT(displayError(QAbstractSocket::SocketError)));
    
        serverStatusLabel->setText(tr("Accepted connection"));
        tcpServer.close();
    

    after connect operation , tcpserver just be closed , what if the transfer not finished ? why the documentary write like this ?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      1. QMessageBox::critical will spin an event loop like QDialog::exec() does hence the application continues to run.
      2. The server is closed but the connection is still opened and the transfer is done between the two QTcpSocket.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      S 1 Reply Last reply
      2
      • SGaistS SGaist

        Hi,

        1. QMessageBox::critical will spin an event loop like QDialog::exec() does hence the application continues to run.
        2. The server is closed but the connection is still opened and the transfer is done between the two QTcpSocket.
        S Offline
        S Offline
        SpartaWHY117
        wrote on last edited by
        #3

        @SGaist said in questions about qtcpserver and socket in Loopback Example:

        Hi,

        1. QMessageBox::critical will spin an event loop like QDialog::exec() does hence the application continues to run.
        2. The server is closed but the connection is still opened and the transfer is done between the two QTcpSocket.

        thanks for your answer , the serve is closed means that this only accept one connection ?

        i have a feature want to achieve is like this example , my program has a backup feature , it use timer to control fixed time interval to transfer some files to same program on the other machine . so if once connection connect , i close the tcpserver , which signal i can use to let me known the transfer finished ? or just set the total size to control ?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          That's up to you to implement since you know what you are transferring. You can use QDataStream::startTransaction for that.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          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