|
|
Hi all,
I have used QTcpSocket and QTcpServer to implement a custom client
server, in which the client can remotely control certain functions on
the server. Everything seems to be working well, but I have issue when
writes to the socket occurs too close together. Only the first write
goes through.
For communication I have created a class called SocketProtocol that
takes care of the protocol. It has a write() method. Simplified it
would look something like this :
void SocketProtocol::write(const QString& string)
{
QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_4_0);
out << (quint16)0;
out << string;
out.device()->seek(0);
out << (quint16)(block.size() - sizeof(quint16));
m_socket->write(block); // m_socket is a pointer to a QTcpSocket instance
m_socket->flush();
}
If I now instantiate and use the protocol :
SocketProtocol *p = new SocketProtocol;
p->write("Test 1");
p->write("Test 2");
// Only Test 1 is received (very infrequently, both are received).
Putting a sleep between the writes have no effect. However, if I
trigger them via QTimer::singleShot() it seems to work.
Any ideas what I might be doing wrong.
Thanks
Marius
--
To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
"unsubscribe" in the subject or the body.
List archive and information: http://lists.trolltech.com/qt-interest/
|
|