Unsolved to send two message with server and to display into two client box in different time
-
Hi I'm usign client/server fortune example.
I want to send two messagge: the first when connection is established and the second after some minutis.
And my server has to send messagge automatically.I have two message in client windows but in the same time. I want two messagge in different time.
Can you suggest ?
So I wrote the code:
SERVER
void Server::sendFortune() { //! [5] QByteArray block; QDataStream out(&block, QIODevice::WriteOnly); out.setVersion(QDataStream::Qt_5_10); fortunes << tr("CONNECTED\n with Seriale Number 1234567890 "); out << fortunes[QRandomGenerator::global()->bounded(fortunes.size())]; QTcpSocket *clientConnection = tcpServer->nextPendingConnection(); clientConnection->write(block); sleep(100); fortunes1 << tr("WARNING\n from Seriale Number 1234567890 "); out << fortunes1[QRandomGenerator::global()->bounded(fortunes1.size())]; clientConnection->write(block); }
CLIENT
:
void Client::readFortune() { while(1) { in.startTransaction(); QString nextFortune; in >> nextFortune; if (nextFortune != currentFortune) { if (count==1) { QMessageBox::information(this, tr("WARNING"), nextFortune); } count++; } statusLabel->setText(currentFortune); }
-
-
it doesnt work :(
Socket thinks two messages are only one message :(
-
@Montanaro Socket does not think anything, it just sends what you tell it to send.
Please post your current code if it does not work the way you want.