questions about qtcpserver and socket in Loopback Example
-
Loopback Example tell me how to use
qtcpsever
andqtcpsocket
. but i have a question in this example .- 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();
- 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 ? - in
-
Hi,
QMessageBox::critical
will spin an event loop likeQDialog::exec()
does hence the application continues to run.- The server is closed but the connection is still opened and the transfer is done between the two QTcpSocket.
-
@SGaist said in questions about qtcpserver and socket in Loopback Example:
Hi,
QMessageBox::critical
will spin an event loop likeQDialog::exec()
does hence the application continues to run.- 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 ? -
That's up to you to implement since you know what you are transferring. You can use QDataStream::startTransaction for that.