<p>I have two unrelated processes that use .NET assemblies as plugins. However, either process can be started/stopped at any time. I can't rely on a particular process being the server. In fact, there may be multiple copies running of one of the processes, but only one of the other.</p>

<p>I initially implemented a solution based off of <a href="http://www.developer.com/net/net/article.php/3520891" rel="nofollow noreferrer">this article</a>. However, this requires the one implementing the server to be running before the client.</p>

<p>Whats the best way to implement some kind of notification to the server when the client(s) were running first?</p>

[{'answer_id': 43068, 'author': 'Eric Z Beard', 'author_id': 1219, 'author_profile': 'https://Stackoverflow.com/users/1219', 'pm_score': 0, 'selected': False, 'text': '<p>Why not host the server and the client on both sides, and whoever comes up first gets to be the server?  And if the server drops out, the client that is still active switches roles.</p>\n'}, {'answer_id': 220256, 'author': 'David B Heise', 'author_id': 13124, 'author_profile': 'https://Stackoverflow.com/users/13124', 'pm_score': 0, 'selected': False, 'text': "<p>There are many ways to handle IPC (.net or not) and via a TCP/HTTP tunnel is one way...but can be a very bad choice (depending on circumstances and enviornment).</p>\n\n<p>Shared memory and named pipes are two ways (and yes they can be done in .Net) that might be better solutions for you. There is also the IPC class in the .Net Framework...but I personally don't like them due to some AppDomain issues...</p>\n"}, {'answer_id': 257969, 'author': 'Garo Yeriazarian', 'author_id': 2655, 'author_profile': 'https://Stackoverflow.com/users/2655', 'pm_score': 2, 'selected': True, 'text': '<p>Using shared memory is tougher because you\'ll have to manage the size of the shared memory buffer (or just pre-allocate enough).  You\'ll also have to manually manage the data structures that you put in there.  Once you have it tested and working though, it will be easier to use and test because of its simplicity.</p>\n\n<p>If you go the remoting route, you can use the IpcChannel instead of the TCP or HTTP channels for a single system communication using Named Pipes. <a href="http://msdn.microsoft.com/en-us/library/4b3scst2.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/4b3scst2.aspx</a>.  The problem with this solution is that you\'ll need to come up with a registry type solution (either in shared memory or some other persistent store) that processes can register their endpoints with.  That way, when you\'re looking for them, you can find a way to query for all the endpoints that are running on the system and you can find what you\'re looking for.  The benefits of going with Remoting are that the serialization and method calling are all pretty straightforward.  Also, if you decide to move to multiple machines on a network, you could just flip the switch to use the networking channels instead.  The cons are that Remoting can get frustrating unless you clearly separate what are "Remote" calls from what are "Local" calls.</p>\n\n<p>I don\'t know much about WCF, but that also might be worth looking into.  Spider sense says that it probably has a more elegant solution to this problem... maybe.</p>\n\n<p>Alternatively, you can create a "server" process that is separate from all the other processes and that gets launched (use a system Mutex to make sure more than one isn\'t launched) to act as a go-between and registration hub for all the other processes.</p>\n\n<p>One more thing to look into the Publish-Subscribe model for events (Pub/Sub).  This technique helps when you have a listener that is launched before the event source is available, but you don\'t want to wait to register for the event.  The "server" process will handle the event registry to link up the publishers and subscribers.</p>\n'}, {'answer_id': 260510, 'author': 'Scott P', 'author_id': 33848, 'author_profile': 'https://Stackoverflow.com/users/33848', 'pm_score': 0, 'selected': False, 'text': "<p>I agree with Garo.</p>\n\n<p>Using a pub/sub service would be a great solution.  This obviously means that this service would need to be up and running before either of the other two.</p>\n\n<p>If you want to skip the pub/sub you can just implement the service in both applications with different end points.  When either of the applications is launched it tries to access the other known object via the IPC proxy.  If the proxy fails, the other object isn't up.</p>\n\n<p>-Scott</p>\n"}, {'answer_id': 1096082, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>I\'ve spent 2 days meandering through all the options available for IPC while looking for a reliable, simple, and fast way to do full-duplex IPC. <a href="http://ipclibrary.codeplex.com/" rel="nofollow noreferrer">IPCLibrary</a>, which I found on Codeplex.com, is so far working perfectly out of all the options that I tried. All with only 7 lines of code. :D If anyone stumbles across this trying to find a full-duplex IPC, save yourself a ton of time and give this library a try. Grab the source code, compile the data.dll and follow the examples given.</p>\n\n<p>HTH,\n Circ</p>\n'}]
['https://Stackoverflow.com/questions/42987', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/645/']