Results 1 to 7 of 7

Thread: LocalSocket and Data Loss

  1. #1

    Arrow LocalSocket and Data Loss

    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?

  2. #2

    Default Re: LocalSocket and Data Loss

    Any ideas?

    Some good example of local socket IPC would be very nice.

  3. #3

    Default Re: LocalSocket and Data Loss

    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?

  4. #4
    Join Date
    Dec 2007
    Posts
    627
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: LocalSocket and Data Loss

    Kindly try to set QLocalServer::setMaxPendingConnections() higher up to 300.

  5. #5

    Post Re: LocalSocket and Data Loss

    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:
    Qt Code:
    1. iSocket = new QLocalSocket(this);
    2. iSocket->connectToServer(aCallbackAddress);
    To copy to clipboard, switch view to plain text mode 
    Sending:
    Qt Code:
    1. iSocket->flush();
    2. int write = iSocket->write(aData.toAscii());
    3. if (write == -1)
    4. {
    5. success = false;
    6. }
    7. iSocket->waitForBytesWritten(MSG_TIMEOUT);
    8. iSocket->flush();
    To copy to clipboard, switch view to plain text mode 

    Receiving:
    Qt Code:
    1. QString data = iSocket->readAll();
    To copy to clipboard, switch view to plain text mode 


    QLocalServer

    Initialization:
    Qt Code:
    1. iServer = new QLocalServer(this);
    2. iSockets = new QMap<QLocalSocket*,QString>();
    3. iServer->listen(aCallbackAddress);
    4. connect(iServer, SIGNAL(newConnection()), SLOT(newConnectonHandle()));
    To copy to clipboard, switch view to plain text mode 

    Sending:
    Qt Code:
    1. if (socket->write(aData.toAscii()) == WRITE_ERROR)
    2. {
    3. success = false;
    4. }
    5. socket->waitForBytesWritten(MSG_TIMEOUT);
    6. socket->flush();
    To copy to clipboard, switch view to plain text mode 


    Receiving:
    Qt Code:
    1. QLocalSocket* socket = 0;
    2. for (int i=0; i < iSockets->keys().count(); i++)
    3. {
    4. if (iSockets->keys().at(i)->bytesAvailable() >= (int)sizeof(quint16))// Socket has some data to read
    5. {
    6. socket = iSockets->keys().at(i);
    7. QString data = socket->readAll();
    8. QStringList messageArgs = data.split(MSG_DELIMETER);
    9. if (messageArgs.count()>2)
    10. {
    11. iSockets->insert(socket,messageArgs.at(2));
    12. }
    13. emit received(data);
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 

    Do you see anything out of place here?

  6. #6

    Smile Re: LocalSocket and Data Loss

    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?

  7. #7

    Question Re: LocalSocket and Data Loss

    Up.

    Question is still open.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.