I'm using QLocalSocket (and QLocalServer) to create IPC in Windows and it works pretty nicely. But when there is lot of traffic, I'm starting to lose messages.
How I should implement IPC with local socket properly to prevent data loss?
Printable View
I'm using QLocalSocket (and QLocalServer) to create IPC in Windows and it works pretty nicely. But when there is lot of traffic, I'm starting to lose messages.
How I should implement IPC with local socket properly to prevent data loss?
Any ideas?
Some good example of local socket IPC would be very nice.
The problem still occurs.
How do you usually manage IPC in windows with Qt and so that it can endure some traffic? Alternatives to QLocalSocket? Or problem code example how to implement QLocalSocket for windows?
Kindly try to set QLocalServer::setMaxPendingConnections() higher up to 300.
What's the default value for maxpendingconnections in windows?
I doubt if this really is the problem, since isn't count of connections the number of local sockets connected to the local server? Because the problem exists even though I only have single use local socket sending and receiving lot of packages from the server.
This is how my code looks like:
QLocalSocket
Initialization:
Sending:Code:
iSocket = new QLocalSocket(this); iSocket->connectToServer(aCallbackAddress);
Code:
iSocket->flush(); int write = iSocket->write(aData.toAscii()); if (write == -1) { success = false; } iSocket->waitForBytesWritten(MSG_TIMEOUT); iSocket->flush();
Receiving:
QLocalServer
Initialization:
Code:
iServer = new QLocalServer(this); iSockets = new QMap<QLocalSocket*,QString>(); iServer->listen(aCallbackAddress); connect(iServer, SIGNAL(newConnection()), SLOT(newConnectonHandle()));
Sending:
Code:
if (socket->write(aData.toAscii()) == WRITE_ERROR) { success = false; } socket->waitForBytesWritten(MSG_TIMEOUT); socket->flush();
Receiving:
Code:
QLocalSocket* socket = 0; for (int i=0; i < iSockets->keys().count(); i++) { if (iSockets->keys().at(i)->bytesAvailable() >= (int)sizeof(quint16))// Socket has some data to read { socket = iSockets->keys().at(i); if (messageArgs.count()>2) { iSockets->insert(socket,messageArgs.at(2)); } emit received(data); } }
Do you see anything out of place here?
It feels a bit like having a monologue here, but I continue...
Got it working finally. :) I feel a bit silly to say, that I didn't take the Windows buffer in account. So to get it working, the message must have a some kind of delimiter at end, because when readyRead is called, the might be more than one message to be read.
One question though. How secure is QLocalSocket?
Up.
Question is still open.