Inter process communication

Hi Experts,

I'd love to get my hands on a class that does IPC with itself - kind of pre-packaged.  I'd inherit from it and add whatever member variables I want to it.  Where can I get this?  It must not have MFC or ATL support - just Win32, STL and Poco is OK too (no managed code)...

Thank you,
Mike
LVL 1
threadyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
phoffricCommented:
I downloaded a 2007 version that also had TCP - many IPC C++ classes in this real project.

UDP sockets:
http://udt.sourceforge.net/index.html

Download:
http://sourceforge.net/projects/udt/
0
cupCommented:
The full list of IPC supported by windows is listed in http://msdn.microsoft.com/en-us/library/aa365574(VS.85).aspx

Even more examples in http://www.codeproject.com/KB/threads/Win32IPC.aspx

If you wish to use IPCs between processors, then you could try

o CORBA
o DCOM (MS version of CORBA)
o SOAP (CORBA in XML through port 80)
o HLA (something from OMG)
o DDS (something from OMG),
o TENA
o Web Services (CORBA in XML over the net)

They're all more or less the same.  All processes advertise their services.  You then request a service from an ORB.  It goes on the ether and gets the answer and replies to you.  These are all scaleable: you can run the whole lot on one processor or multiple processors or even multiple machines.  Only problem is that your machine has to be connected to a hub/switch: not so good for demos on laptops.

The simpler ones like mailslots (used by net send) and sockets (winsock mentioned by phorrfic) will work from Windows 3.1 through to Windows 7.
0
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

evilrixSenior Software Engineer (Avast)Commented:
The Boost library has a plethora of cross-platform interprocess classes
http://www.boost.org/doc/libs/1_42_0/doc/html/interprocess.html
0
itsmeandnobodyelseCommented:
>>>> a class that does IPC with itself

Can you tell what you mean by 'itself'?

IPC means at least two processes. If both were written by you, they can use the same utiltity class which for example could provide access to shared memory. Do you mean something like that?

0
jkrCommented:
Since your IPC issue is most likely related to your previous Q at http://www.experts-exchange.com/Programming/System/Windows__Programming/MFC/Q_25754292.html I'd like to go back to the article I linked there: http://www.codeproject.com/KB/threads/Win32IPC.aspx  ("Windows IPC"). To signal a status change to your tray icon app, you don't have to send a any classes at all, a simple message like "#statuschange|READY" or  "#statuschange|BUSY" will do to have it display the correct symbol, e.g.
#include "stdafx.h"

#include "windows.h"
#include <string.h>


//Name given to the pipe

#define g_szPipeName "\\\\.\\Pipe\\MyNamedPipe"
//Pipe name format - \\.\pipe\pipename


#define BUFFER_SIZE 1024 //1k

#define ACK_MESG_RECV "Message received successfully"

int main(int argc, char* argv[])
{
     HANDLE hPipe;
     
     hPipe = CreateNamedPipe( 
          g_szPipeName,             // pipe name 

          PIPE_ACCESS_DUPLEX,       // read/write access 

          PIPE_TYPE_MESSAGE |       // message type pipe 

          PIPE_READMODE_MESSAGE |   // message-read mode 

          PIPE_WAIT,                // blocking mode 

          PIPE_UNLIMITED_INSTANCES, // max. instances  

          BUFFER_SIZE,              // output buffer size 

          BUFFER_SIZE,              // input buffer size 

          NMPWAIT_USE_DEFAULT_WAIT, // client time-out 

          NULL);                    // default security attribute 

     
     if (INVALID_HANDLE_VALUE == hPipe) 
     {
          printf("\nError occurred while " 
                 "creating the pipe: %d", GetLastError()); 
          return 1;  //Error

     }
     else
     {
          printf("\nCreateNamedPipe() was successful.");
     }
     
     printf("\nWaiting for client connection...");
     
     //Wait for the client to connect

     BOOL bClientConnected = ConnectNamedPipe(hPipe, NULL);
     
     if (FALSE == bClientConnected)
     {
          printf("\nError occurred while connecting" 
                 " to the client: %d", GetLastError()); 
          CloseHandle(hPipe);
          return 1;  //Error

     }
     else
     {
          printf("\nConnectNamedPipe() was successful.");
     }
     
     char szBuffer;
     DWORD cbBytes;
     
     //We are connected to the client.

     //To communicate with the client 

     //we will use ReadFile()/WriteFile() 

     //on the pipe handle - hPipe

     
     //Read client message

     BOOL bResult = ReadFile( 
          hPipe,                // handle to pipe 

          szBuffer,             // buffer to receive data 

          sizeof(szBuffer),     // size of buffer 

          &cbBytes,             // number of bytes read 

          NULL);                // not overlapped I/O 

     
     if ( (!bResult) || (0 == cbBytes)) 
     {
          printf("\nError occurred while reading " 
                 "from the client: %d", GetLastError()); 
          CloseHandle(hPipe);
          return 1;  //Error

     }
     else
     {
          printf("\nReadFile() was successful.");
     }
     
     printf("\nClient sent the following message: %s", szBuffer);
     
     if (szBuffer == strstr(szBuffer,"#statuschange")) // check for '#statuschange'
     {
        // this is a command for us

        char* pMnemonic = strchr(szBuffer,'|');

        if (pMnemonic)
        {
          // syntax seems to be valid

          *pMnemonic = '\0'; // split off from command

          pMnemonic++; // advance

          if (!strcmp(pMnemonic,"READY"))
          {
            // displey "READY" icon"
          }

          if (!strcmp(pMnemonic,"BUSY"))
          {
            // displey "BUSY" icon"
          }
        }
        else
        {
            // invalid command format, ignore...
        }
     }
     
     strcpy(szBuffer, ACK_MESG_RECV);
     
     //Reply to client

     bResult = WriteFile( 
          hPipe,                // handle to pipe 

          szBuffer,             // buffer to write from 

          strlen(szBuffer)+1,   // number of bytes to write, include the NULL 

          &cbBytes,             // number of bytes written 

          NULL);                // not overlapped I/O 

     
     if ( (!bResult) || (strlen(szBuffer)+1 != cbBytes))
     {
          printf("\nError occurred while writing" 
                 " to the client: %d", GetLastError()); 
          CloseHandle(hPipe);
          return 1;  //Error

     }
     else
     {
          printf("\nWriteFile() was successful.");
     }
     
     CloseHandle(hPipe);
     return 0; //Success

}

Open in new window

0
threadyAuthor Commented:
Wow- lots to look through - thanks for the answers everyone.  To answer some questions - by "a class that talks to itself", I mean it's setup to be a client and server of itself - so that when I use the class in different processes, it "knows" how to connect to the local machine (because that's the only context I'm interested in) and talk to itself.  I'd of course have to change the ports, but that's all I want to do... It probably would have been easier to just setup a client/server class myself for this, but I figured there must be something better that's already done.

jkr, yes, it does correspond to my previous question - however, the icon program will also be sending events back to the service.  Could I modify your code so that it's bi-directional with the server over the named-pipe?

I was leaning more towards sockets, just because it's all I've ever used for IPC, but maybe it's time to try the named pipes...  Hmmm.....
0
jkrCommented:
It is already bidirectional, just scroll down a little bit ;o)
     strcpy(szBuffer, ACK_MESG_RECV);
     
     //Reply to client

     bResult = WriteFile( 
          hPipe,                // handle to pipe 

          szBuffer,             // buffer to write from 

          strlen(szBuffer)+1,   // number of bytes to write, include the NULL 

          &cbBytes,             // number of bytes written 

          NULL);                // not overlapped I/O 

Open in new window

0
threadyAuthor Commented:
I meant to ask - can either side initiate sending messages?
0
jkrCommented:
Either side can, but I'd rather have one be the server or the client to keep things less confusing regarding the protocol you'd use.
0
itsmeandnobodyelseCommented:
>>>> more towards sockets, just because it's all I've ever used for IPC, but maybe it's time to try the named pipes...  

You also might try the shared memory which is the fastest IPC on a local computer. The malfit is that you would need to write your own protocol ...

When using shared memory for IPC you need a sufficiently sized piece of shared memory where you implement two queues, one for each direction. These queues in the easiest forms would contain arrays with fixed-sized records, where each record takes a message (from, to, text). Additionally there is the number of messages currently filled in, the index of the next free slot (to write) and the index of the slot to read next. That all could handled by one class which also would do the house-keeping and the manage the shared access to the memory. The class would provide an interface where you could put and get messages from either queue and all other things were done in the back.
0
threadyAuthor Commented:
Thanks for all the great help!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.