Results 1 to 5 of 5

Thread: Named Pipe Implementation with QLocalSocket - Windows XP

  1. #1
    Join Date
    Jun 2012
    Posts
    58
    Thanks
    13
    Qt products
    Qt4

    Question Named Pipe Implementation with QLocalSocket - Windows XP

    {using Qt 4.7.4 with both MinGW 4.4.0 and Visual Studio 2010}

    Requirement: An Application shares its data via overlapped, write-only, message mode pipe. It only writes to the pipe if update is required. I need to read this pipe if data is available and process the updated data else if no new data is available then process the last read data.

    I'm new to the concepts of pipes in windows. From whatever little that i'v come to know by reading a few articles this is what i am doing:
    Qt Code:
    1. //QLocalSocket namedPipe, QByteArray byteArray and QTimer timer are available as member variables.
    2. QString pipeName="Get it from Registry";
    3. connect(&namedPipe,SIGNAL(connected()),this,SLOT(sloConnected()));
    4. connect(&namedPipe,SIGNAL(error(QLocalSocket::LocalSocketError)),this,SLOT(sloConnectionError()));
    5. namedPipe.connectToServer(pipeName,QIODevice::ReadOnly);
    6.  
    7. void ClassName::sloConnected()
    8. {
    9. connect(&timer,SIGNAL(timeout()),this,SLOT(sloProcess()));
    10. timer.start(200); //i need to update my clients with the changed/unchanged data at regular intervals
    11. }
    12.  
    13. void ClassName::sloProcess()
    14. {
    15. if(namedPipe.bytesAvailable())
    16. byteArray=namedPipe.readAll();
    17. //deal with byteArray. if no bytes were available assume it'll contain valid data from one of the previous reads when data was available
    18. }
    19.  
    20. void ClassName::sloConnectionError()
    21. {
    22. qDebug() << "ERROR!!";
    23. }
    To copy to clipboard, switch view to plain text mode 
    The Application that creates and writes to the pipe keeps running. The problem is that when i close my program and re-run it, it prints "ERROR!!".
    <1> Is it normal for the pipe to vanish after i've connected-to-it and/or attempt-to-read-it once?
    <2> Am i doing something conceptually wrong here?
    <3> Can you please give me a hint on better solution if this is wrong/poor?

    Thanks !!

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Named Pipe Implementation with QLocalSocket - Windows XP

    surely you just need to cleanup the socket when your app exits

    http://doc.qt.nokia.com/4.7-snapshot...nectFromServer

    ?
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Jun 2012
    Posts
    58
    Thanks
    13
    Qt products
    Qt4

    Default Re: Named Pipe Implementation with QLocalSocket - Windows XP

    Quote Originally Posted by amleto View Post
    surely you just need to cleanup the socket when your app exits

    http://doc.qt.nokia.com/4.7-snapshot...nectFromServer

    ?
    i didn't get you. What i'm asking is, does the pipe gets destroyed when my QLocalSocket object that connected to it got destroyed? Or is it just the connection between my application and the application that created the pipe that gets destroyed? I want multiple threads in my application to access the pipe that was created by the other application. If one of the thread ends, the pipe should not get destroyed and let other threads access it. Is this possible with pipes?

  4. #4
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Named Pipe Implementation with QLocalSocket - Windows XP

    "does the pipe gets destroyed when my QLocalSocket object that connected to it got destroyed?"
    Depends on the software running the server, I guess, but I wouldn't have thought so.

    "If one of the thread ends, the pipe should not get destroyed and let other threads access it. Is this possible with pipes?"
    Yes.


    http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  5. #5
    Join Date
    Jun 2012
    Posts
    58
    Thanks
    13
    Qt products
    Qt4

    Default Re: Named Pipe Implementation with QLocalSocket - Windows XP

    thank you. Just one quick question while i read the link you gave me more. QLocalSocket can be used as a full-fledged pipe in the same way as the functions for named pipes in the link you gave right? Or is it recommended to use the windows (non-qt) way?

Similar Threads

  1. QLocalSocket Synchronicity
    By matic in forum Qt Programming
    Replies: 0
    Last Post: 25th March 2010, 12:04
  2. No process is on the other end of the pipe
    By Luc4 in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 7th March 2010, 00:26
  3. QFileDialog to stderr: Couldn't open named pipe (2)
    By Ballig in forum Qt Programming
    Replies: 0
    Last Post: 17th January 2010, 13:30
  4. IPC with QLocalServer/QLocalSocket
    By ManuMies in forum Qt Programming
    Replies: 1
    Last Post: 11th February 2009, 20:09

Tags for this Thread

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.