Finnaly i've find a better solution for my problem. Here it is:
Server.c
while(1){
//...
printf("[SERVER] Waiting for a client... (ConnectNamedPipe)\n");
if(!ConnectNamedPipe(hPipe, NULL)){
perror("Connection Error!");
//exit(-1);
}
CreateThread(NULL,0,ListenClient,(LPVOID)hPipe,0,NULL);
}
Everytime that a client gets his named pipe created, gets aswell a new Thread and in the "ListenClient" function:
DWORD WINAPI ListenClient(LPVOID param) { ... }
which will read the information passed through the pipe like:
ret = ReadFile(hPipe, buf, 256,(LPDWORD) &n, NULL);
if (!ret || !n)
perror("Error reading the named pipe!");
buf[n] = '\0';
there will be as many conditions as the options that each client can request from the server, like:
if(strcmp(buf, "Logon")==0)
{
//process the resquest
}
if(strcmp(buf, "Register")==0)
{
//process the request
}
and so on..
This way the server will read from the buffer and do a simple string compare on the first argument sent.
Thank you all and i hope it helps someone!