3

I have two applications and I used named pipes to communicate between them. The pipes is working absolutely fine thanks to a code project article. But I noticed that if both the apps don't start. Application 'A' keeps waiting for application 'B' and app 'A' does not start. The following is a snippet which creates an aync pipe:

            NamedPipeServerStream pipeServer = new NamedPipeServerStream(PipeName, PipeDirection.In, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);

            pipeServer.BeginWaitForConnection(new AsyncCallback(WaitForConnectionCallBack), pipeServer);

This is the same way I create the pipes in both App 'A' and 'B',each of the applications would have a client as well. This is how I send messages from the client:

NamedPipeClientStream pipeStream = new NamedPipeClientStream(".", PipeName, PipeDirection.Out, PipeOptions.Asynchronous);

            // The connect function will indefinitely wait for the pipe to become available
            // If that is not acceptable specify a maximum waiting time (in ms)
            pipeStream.Connect(TimeOut);

            byte[] _buffer = Encoding.UTF8.GetBytes(SendStr);
            pipeStream.BeginWrite(_buffer, 0, _buffer.Length, AsyncSend, pipeStream);

So how can I improve the performance so that both the applications run without waiting? As of now,I have kept a timeout of 1000 ms. Should I reduce the timeout period? Or am I missing something,which looks likely :)

Aster Veigas
  • 866
  • 3
  • 13
  • 34
  • http://stackoverflow.com/questions/11435262/c-asynchronous-namedpipeserverstream-understanding – ilansch Aug 01 '13 at 18:28
  • both the applications will be on the same machine. WCF creates a local server isn't it? – Aster Veigas Aug 02 '13 at 05:30
  • WCF server-client infra can be inside Managed application (your regular console/application), can be inside Windows service or IIS, i have built a project that i have 2 processes, both contains WCF services and proxy to communicate with each other. it works very good. but it depend if this is what you need. – ilansch Aug 02 '13 at 10:14
  • You will have 2 classes - a proxy client class, and a service host class that receive calls from client.. client class in one process, servicehost class in the other, and both project must know the service interface (the operations) – ilansch Aug 02 '13 at 10:15
  • I did see the namedpipes in WCF but since it was using localhost, I dint want to use it. But let me try it again, if its improving the performance of my application will opt for it :) – Aster Veigas Aug 02 '13 at 10:25
  • You should use whatever is good for your design. alot of application uses WCF and the internet is full with documentation and samples and also in SO.. – ilansch Aug 02 '13 at 11:13
  • Thanks ilansch for your advice. I had reviewed the WCF for this application but I felt it was unnecessary to host a port through WCF. But let me have a look at it again :) – Aster Veigas Aug 02 '13 at 16:25
  • 1
    SO is much more effective when asking question about WCF.. very helpful – ilansch Aug 02 '13 at 20:20

0 Answers0