Click here to Skip to main content
15,353,818 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two applications running on the same physical machine that need to send messages to each other. Named pipes look like a good solution.

I've read about these and found a few nuget packages that appear to do the heavy-lifting but all of the ones I have found seem to revolve around the client/server model.

My problem is that I have no way of knowing which application will start first. What is a good way of handling this?

Note: only one instance of each application is allowed and this is enforced in code.

My apologies if this question is premature. When I actually dig into real code, the answer may well become obvious. I'm on a bit of a tight schedule and hoping someone can stop me wasting time on a dead end.

What I have tried:

I considered having both client and server in each application.

I also considered having a third Relay application that always starts first and simply bounces messages between the two applications but this seems like overkill.
Posted
Updated 18-Feb-22 0:24am

I'd probably use Sockets rather than named pipes as they are a bit more flexible - at a later date it's simple to make them work across multiple machines on a network - you can do that with pipes, but Sockets just provides an extra layer of abstraction and hides the messy details.

If you aren't sure which app starts first then the simplest solution is to have each app open a client socket when it starts - if the client fails to connect, then open a server instead.
   
Comments
Patrick Skelton 18-Feb-22 4:03am
   
Thank you!
My advice would be to use MessagingQueue, For client-side behavior Application read messages from Queue, similarly for server-side behavior application can send messages to Messaging Queue.

This can also scale easily if both applications reside on different machines. On top of that number of applications from two to n can also get scale.
   
Comments
Patrick Skelton 21-Feb-22 2:48am
   
Thank you for the suggestion. It does look interesting. I'd have to do a bit of logic to code around the fact that I don't want one application to be able to send a message that is some-time-later processed by the second application (i.e. I'm only interested in the case when both applications are currently running simultaneously) but I can't see that being too difficult. Definitely an option.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900