Hi,
I'm writing a service that will occasionally receive commands from a Windows Client telling it what actions to perform. I've attached a Timer with an elapse time of 1 second to check to see if anyone has connected to the NamedPipe and if so, what's the action requested.
The Service creates the ServerNamedPipe in the OnStart method and the Client connects to the pipe. What I'm seeing happening, is the client successfully connects to the Pipe ("Pipe Connected" message in the trace. I verified the pipe connection through ProcessExplorer, however the Server never shows the pipe being connected. This is proven by the lack of the message "Client is connected" in the trace and nothing that follows is taking place either. I verified the firing of the timer even by adding a Trace.WriteLine before the check for IsConnected and those trace messages appear.
I've been wracking my brain for hours trying to figure this one out. Anyone see what I've done wrong, it's not obvious to me.
PS - Everything is in a try/catch block and I'm not seeing any exceptions written either.
Thank you for your time and help!
Regards,
Glenn
NamedPipeServerStream pipeServer = null;
internal const string ServerName = ".";
internal const string PipeName = "CmdCollector";
internal const string FullPipeName = @"\\" + ServerName + @"\pipe\" + PipeName;
internal const int BufferSize = 1024;
PipeSecurity pipeSecurity = new PipeSecurity();
pipeSecurity.SetAccessRule(new PipeAccessRule("Authenticated Users",
PipeAccessRights.ReadWrite, AccessControlType.Allow));
pipeSecurity.SetAccessRule(new PipeAccessRule("Administrators",
PipeAccessRights.FullControl, AccessControlType.Allow));
if (pipeServer == null)
{
pipeServer = new NamedPipeServerStream(
FullPipeName,
PipeDirection.InOut,
NamedPipeServerStream.MaxAllowedServerInstances,
PipeTransmissionMode.Message,
PipeOptions.None,
BufferSize,
BufferSize,
pipeSecurity,
HandleInheritability.None
);
work = string.Format("{0} {1} - OnStart Pipe Created",
ProductName, DateTime.Now);
Trace.WriteLine(work);
}
if (pipeServer.IsConnected == false)
return;
work = string.Format("{0} {1} - Client is connected",
ProductName, DateTime.Now);
Trace.WriteLine(work);
Trace.Flush();
internal const string ServerName = ".";
internal const string PipeName = "CmdCollector";
internal const string FullPipeName = @"\pipe\" + PipeName;
internal const int BufferSize = 1024;
work = string.Format("{0} {1} - sendRunCollection - Run Collection Entry",
Application.ProductName, DateTime.Now);
Trace.WriteLine(work);
pipeClient = new NamedPipeClientStream(
ServerName,
FullPipeName,
PipeDirection.InOut,
PipeOptions.None);
pipeClient.Connect(5000);
if (pipeClient.IsConnected == false)
{
work = string.Format("{0} {1} - sendRunCollection - Pipe failed to connect",
Application.ProductName, DateTime.Now);
Trace.WriteLine(work);
MessageBox.Show("Pipe failed to connect", "Cmd Controller",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
else
{
work = string.Format("{0} {1} - sendRunCollection - Pipe connected",
Application.ProductName, DateTime.Now);
Trace.WriteLine(work);
}