From NamedPipeClient how can I tell if I am connected?
Opened this issue · 4 comments
When connecting from the client, there seems to be no way to tell if there server is actually running and the connection is up. In the following code:
_pipe = new NamedPipeClient<OA_Message>(PipeName);
_pipe.ServerMessage += _pipe_ServerMessage;
_pipe.Error += (ex) => _error = ex.ToString();
_pipe.Disconnected += _pipe_Disconnected;
_pipe.Start();
_pipe.WaitForConnection(300);
Everything goes fine as if it worked, except that the server is not running the the pipe is not connected. Within the NamedPipeClient there is a protected member _connection that is NULL in this case, but I can't check it because it is private. It seems like there should be some kind of IsConnected property, or that the Error callback should be called if there isn't a server to connect with...
Am I missing something?
Why don't you just send a message to the client once it connects to the server? Later on you can use the client.Disconnected event handler.
@buhralex it still would leave you to guess if the message from the client failed to come for some other reason. Since I had the code I simply solved it by adding the property I suggested and it works perfectly. It doesn't look like people are falling over themselves to release new versions of this anyway.
During the communication in channel either the server or client stops working there we can use disconnected() method in NamedPipeStream to check if the server or the client is up before sending the message. After checking the disconnected status we can try reconnecting to the channel.
Please help me how can I check if the connection is up and try reconnecting to the channel.
Please help me how can I check if the connection is up and try reconnecting to the channel.
Send a specific message to the server, e.g. "ConnectionTest".
Create a workaround in the server that reacts to the "ConnectionTest" message and sends a message back directly to the client ("ConnectionSuccessful").
If the client receives a "ConnectionSuccessful" message after sending the "ConnectionTest" message, you know that the server is online and the client is connected.