Design Patterns – Simplest Way to Broadcast Data Between Applications in .NET

design-patternsnet

I want to send information from one .Net application to multiple other .Net applications. I want the applications to be loosely coupled. The number of applications receiving the information could change at run time. What is the simplest way to do this?

I thought about using MSMQ, but from what I can tell, there the broadcasting application has to know how many receivers there are or each message only gets processed by one of the receiving applications. Neither options is acceptable.

Best Answer

One solution would be to publish the information via UDP. Open a specific port for broadcasting, send your data. There is nothing else to do on the provider/server side.

On the client side, open the same port for receiving.

The only downside that I am aware of with this method is that if you miss the broadcast message, you will never see it again. There is no guaranteed delivery.

One upside is that you can have unlimited clients with no additional overhead for the server.

Microsoft has a working example using the UDPClient class.

If you need guaranteed delivery, you can use (among other options) the TCPListener class for your server. You will have to use the TCPClient class for the client. This technique will (more or less) recreate a web server and clients. Writing a RESTful interface would be easier.

One downside is that every client opens a connection (more overhead) to your server.

Related Topic