Pipes


#1

Hi,

I’ve got a daemon written with juce using InterprocessConnection Class to create a Pipe.
My client, can’t use juce, so i’am trying to use native windows API to send messages to my daemon.
My client successfully connect to the daemon but when i send data, my daemon doesn’t receive anything.
What am i doing wrong ?

Here is my client code :

int main(int argc,char** argv){
cout << “Test pipe” << endl;

HANDLE hPipe;
DWORD dwWritten;

char *pszPipe = "\\\\.\\pipe\\midiauthpipe";

// Test if pipe exists
if (  WaitNamedPipe(pszPipe, 1000) == 0 ){
	cout << "WaintNamePipe error : " << GetLastError() << endl;
}

// Create pipe handle
hPipe = CreateFile(pszPipe, GENERIC_READ | GENERIC_WRITE, 0, 0,OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);


// Test handle validity
if (hPipe == INVALID_HANDLE_VALUE) {
     cout << "invalid pipe handle" << endl;
	 exit(-1);
} else {
cout << "Pipe seems correctly opened" << endl;
}

// asynchrnous write
char huhu[512]="fzngfjnezjnzejgnzejgnzejnjgnzejgnejzungezgnjezgnzjgnzejnezjngjueznjngejzn";
WriteFile(hPipe, huhu, 512, &dwWritten, NULL);


// Cleaning
DisconnectNamedPipe(hPipe);
CloseHandle(hPipe);

}

Help me !!!

Thx.

Denis.


#2

when you use those classes the messages have a special header

InterprocessConnection (const bool callbacksOnMessageThread = true,
                            const uint32 magicMessageHeaderNumber = 0xf2b49e2c);

each message has this header before the data, the header consists of this number and the message length, take a look at the juce_InterprocessConnection.cpp file to see how this works.


#3

thx, it’s working now.