[Qt-interest] Question on QTcpSocket & QTcpServer
David Boosalis
david.boosalis at gmail.com
Fri Oct 16 23:19:19 CEST 2009
Hi
I have an application that uses QTcpSocket on the client and the server uses
QTcpServer. Everything works fine if I do one request from the client to the
server, but I want to do multiple request and this is where it fails.
MyApp::connectedSlot()
{
// ok have caught the signal to tell me I am connected to the server. So
now I send my request(s)
QByteArray block;
qint64 numBytes;
QDataStream out(&block,QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_4_0);
out << (quint16) 0;
out << (quint16) ServerMessage::GetUsers;
out.device()->seek(0);
out << (quint16) (block.size() - sizeof(quint16));
numBytes = serverSocket->write(block);
//I want to send another request and this is where I get an error on the
server
block.clear();
out.device()->seek(0);
out << (quint16) 0;
out << (quint16) ServerMessage::GetProfiles;
out.device()->seek(0);
out << (quint16) (block.size() - sizeof(quint16));
numBytes = serverSocket->write(block);
}
If I put debug lines in my client code above I get no errors. However on
the serve side I get a socket disconnect followed by a connected and only
see the first request for users.
Can I not write to a socket with back to back calls like this. I would
think they would be queued. I was looking for something like a
socket->isReady() but could not find any such method. Of course I could
bundle the two request to the server as one request, but was wondering what
I am not understanding about TcpSockets.
Any advise as to why my double request to the serve does not work is
appreciated.
I am using Qt 4.6 tpl1 by the way
-David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091016/af0ed4cb/attachment.html
More information about the Qt-interest-old
mailing list