Dalibor Čarapić
Dalibor Čarapić

Reputation: 3142

WCF Net.TCP: Most efficient way to broadcast messages to a lot of clients

I have a WCF service hosted with Net.TCP binding to which a lot of clients (> 100) may connect and receive various broadcast messages. The same message is sent to all clients and the current way I'm currently doing it is to have dedicated thread which waits on a BlockingCollection for new messages and as soon as new message arrives it iterates over the list of client callback connections and calls a method which receives the message as an argument.

So my code currently looks like this:

var msg = ... get message from queue ...
foreach(var client in clients)
    client.SendMessage(message)

This design has following problems:

  1. Clients can not receive new message until I'm finished sending a message to all clients
  2. I would like to detect slow clients and possibly disconnect them
  3. The message is being serialized as many times as I have clients (I could change it so that I serialize the message before sending it but I would need to change the signatore of SendMessage to SendMessage(byte[] content) and this is not something I would like to do)

Does anybody has experience with such problems? Any tips/tricks/hints?

Upvotes: 3

Views: 2051

Answers (1)

Yury Schkatula
Yury Schkatula

Reputation: 5369

It seems you have to use multicasts instead of dedicated communication. So each new client will need to join the cast channel (see IGMP for details) and then your server will fire-and-forget once per message you need to publish.

Upvotes: 1

Related Questions