Hey
@tbscope:
I am aware of the legal implications such an endeavor can have. Hence I made it very clear to my superiors that I need assurance that it won't backfire. Good point though, I should be putting that insurance in letters and get it signed.
@wysota:
Yes, that's why I didn't go for the multi-threaded server. It has way too much overhead. Not getting data in is also on the list since the solution will have a mobile component to it and those devices can go off-grid any time. I figured that something along the lines of
void Server::onReadyRead() {
QTcpSocket *client
= qobject_cast<QTcpSocket
*>
(sender
());
if(!client)
return;
int blockSize = 0 ;
if (blockSize == 0) {
if (client->bytesAvailable() < (int)sizeof(quint16))
return;
in >> blockSize;
}
if (client->bytesAvailable() < blockSize)
return;
in >> incomingData;
doStuff(incomingData);
}
void Server::onReadyRead() {
QTcpSocket *client = qobject_cast<QTcpSocket *>(sender());
if(!client)
return;
int blockSize = 0 ;
QString incomingData;
QDataStream in(client);
in.setVersion(QDataStream::Qt_4_7);
if (blockSize == 0) {
if (client->bytesAvailable() < (int)sizeof(quint16))
return;
in >> blockSize;
}
if (client->bytesAvailable() < blockSize)
return;
in >> incomingData;
doStuff(incomingData);
}
To copy to clipboard, switch view to plain text mode
should do the job. On top of that is a timer that let's each connection time out after a set period of time. (The client pings the server to confirm its status)
Thanks for the advice, it's really helpful to get a different perspective on things.
Alex
Bookmarks