I have to create a client server named pipe system. I use the named pipe wrapper.
if (npClient == null)
npClient = new NamedPipeClient<NamedPipeExchangeClass>(CConstants.NAMEDPIPE_NAME);
npClient.Start();
npClient.Error = NpClient_Error;
npClient.Disconnected = NpClient_Disconnected;
npClient.ServerMessage = NpClient_ServerMessage;
npClient.WaitForConnection(3000);
I have stopped the server and didn't get any error.
so how can if after that the client is connected or not? Please notice that 3000 is the timeout therefore if I don't put it the dll will wait indefinitely for its connection. Obviously I could put it in a thread and see if it exits using a variable.
But I really am astonished that there's no member indicating if the connection has succeded or not and even all the functions are void and not bool.
I have seen other posts in which they suggested to use a mutex to detect the present of the server. But presence doesn't means connection ok.
Even pushing a message to the server (which doesn't exist) won't cause any error. Thanks for helping
Patrick
--- EDIT --- I have seen that when the client connects to the server, the latter sends an empty message. I can use this with a timer to detect the connection. But once again I feel it's weird not being able to know if the client is connected or not after the timeout
CodePudding user response:
When no server exists, the Start
method will stick at this line permanently, you cannot know whether if the connection is established.
var handshake = PipeClientFactory.Connect<string, string>(_pipeName,_serverName);
So if you want to keep using this package, you need guarantee a working server. And I found a similar issue, it was committed on 2018 ....