Best Practices for ID'ing Messages Master->Slave (IPC)

Hi all, I’m wondering if anybody’s got a good suggestion to how one can ID messages when sending from ChildProcessMaster to ChildProcessSlave:

struct MessageContent
{
    double attribute1;
    double attribute2;
    String attribute3;
    File attribute4;
};

ChildProcessMaster::sendMessageToSlave (const MemoryBlock& m)
{
    MessageContent content;
    // wrap up content and send to Slave
}

ChildProcessSlave::handleMessageFromMaster (const MemoryBlock& m)
{
    // check to make sure this is contains a MessageContent instance
}

I was thinking of creating an int64 ID and appending it to the front of the memory block and check for that (in addition to the size).

Many thanks!

This is already done. If you look at the sources, you see that the connection used is inheriting InterProcessConnection, which uses a magic number to verify that the message comes from a source using the same protocol:

In InterProcessConnection you see, that the header is indeed a 32 bit integer as magic number followed by a second 32 bit integer stating the size of the packet.

Hope that helps…

Hey daniel thanks for the reply. I should have specified: how to create an ID system between the Master/Slave for different kinds of custom messages. There’s some code to go off of in juce_ConnectedChildProcess.cpp where the size is checked and then a sort of identifier is checked (its an 8 byte char string in that case). I was just wondering if there are any pitfalls I should look out for when implementing such an ID system for larger messages.

You might want to look at how we do this in the projucer, for communicating with the child process that does the compiling. It’s in projucer_ClientServerMessages.h

ok thanks I’ll take a look