In order to implement a network application that uses multicasts to send small periodic messages to other processes in the network, what choices do I have with regard to using APIs in the .Net framework? Apart from my obvious current choice, the System.net.sockets API, does WCF provide a simpler approach? Or is WCF purely a point-to-point SOA-based IPC mechanism?
Note: I'm quite conversant with the implementation details of multicast programming. What I am interested in hearing is what other choices the .Net framework offers.
I was going to suggest that use callback channels (i.e. a pub/sub type system) implemented in WCF, but that would require your clients to register with the 'server'.
I was then going to mention enterprise class messaging solutions like Tibco EMS (a JMS implementation).
Then I hit google and found this link: WCF Multicasting. There are lots of ideas on there which I've not yet come across in my own inital look at WCF.
You just create a UDPClient
and send data to a multicast address (224/4
, that is any address from 224.0.0.0
to 239.255.255.255
).
Your clients just listen on this address as usual.
See my answer here for more details.
P.S. Though WCF
is quite an overkill for such a simple task, it's perfectly possible with WCF
. There are different Message Exchange Patterns
there, i. e. the ways the communication flows.
What you need is IOutputChannel
for the sender and IInputChannel
for the listeners, these are datagram oriented patterns.
WCF is REALLY heavy for what you want to do.
Your best bet really is using the datagram's in the sockets api. They aren't too scary once you get your head around the API, but it certainly isn't the friendliest one available.
Multicasting is achieved via the address that is being sent to provided that your ISP / Network admin allows multicast data. WCF inherently doesn't allow multiple targets AFAIK, when you create a proxy, you must point it at an IP (which could be a multicast address)
FWIW, your initial question asked specifically whether WCF could achieve your goals. As Quassnoi indicated earlier you can certainly do this using WCF. While most of the literature about WCF is focused around how you use it's contract model, its possible and plausible to just use the channel model and binding structure.
If you implement the IOutputChannel and IInputChannel you can create your own datagram based channel. Is this provided as part of the framework no (and I think this is also core to your question). However, Microsoft did provide a sample of a UDP transport (which they claim supports multicast). You can find their sample at the following URL:
来源:https://stackoverflow.com/questions/515572/multicast-support-in-net