2

My program:

  1. Different Clients connect to the Server (User login)

  2. Then server starts to Push small data ( below 1KB ) to all of them every second (or less).

My questions:

  1. What service should I use? is WCF the right one?
  2. If WCF, then which protocol to use ? http, tcp ... ?

At first I thought WCF is the right thing to go with. I implemented a basic simple. Then suddenly I noticed this is only a Client to Server connection. and Server can't communicate the same way to client. Unless I start the service on client as well which makes it a server.

So in the end, I am asking how should I impelement this 2 way communication between server and client, considering the speed factor I mentioned and the right protocol to use.

UPDATE

Ok let me add some details. This is actually a Teacher client < > Server < > Students client communication program. Teacher draws something on a WPF's inkCanvas. and this drawing is supposed to be pushed to all students clients. That's why this data should be pushed by the server. and the communication has to be 2 way.

xperator
  • 2,743
  • 7
  • 34
  • 58

4 Answers4

1

One possibility is to look at using a network library. Have a look at this article on using NetworkComms.Net to create a WPF chat application. The client -> server, server -> client relationship is symmetrical as opposed to WCF so push notifications are completely straight forward. You also have achoice of communication protocols, e.g. TCP or UDP, and can easily add your own extensions for processing outgoing/incoming data.

Disclaimer - I'm a developer for this library.

MarcF
  • 3,169
  • 2
  • 30
  • 57
  • wow thanks! the library code samples look very easy. gonna start working on it in a few minutes. But can you please tell me why you suggest to use this over WCF – xperator Apr 28 '13 at 16:40
  • It's definitely a matter of preference and coding background, you could achieve the same with both. IMHO (and I accept I am possibly a little biased) NetworkComms.Net is more powerful than WCF and certainly easier to implement. – MarcF Apr 28 '13 at 16:45
1

I implemented exactly same functionality to communicate between two WPF application. To answer your question, Yes, in my opinion WCF is the best way to go. I guess you have already implemented One way communication using WCF. To be able to have Server to talk back to clients you need to implement Callbacks, here is a good article to start with.

0

You're better off not to have the Server PUSH data to it's clients but rather have the clients PULL data from the Server. Although, this is possible with duplex, it is not highly recommeneded as most ISP or server environments, will not allow outbound messages from within their firewalls for security reasons.

Here's my suggestion:

Have the client application(s) occationally pull from the server rather than have the server push to it's clients. This way, the server doesn't have to have a constant connection, because it doesn't scale and more importanly communication connections are very expensive resources from one application (i.e. Server).

Redesign your approach.

code5
  • 4,434
  • 2
  • 31
  • 24
  • Ok I added an Update to my post. That's the reason why I need the server to push the data. – xperator Apr 28 '13 at 16:36
  • I think @xperator is right. In your case Student client should do refreshing of data from server in a cyclic way for checking the data from Teacher client. Then you must provide the two kinds of client. – Bronek Apr 28 '13 at 17:03
  • Thanks for the update. My approach still stands as a better solution from a scalability perspective. This is how a message bus for example works via a pub/sub model. It may seem that the sub gets notified but in reality the client pulls the data. To help you visualize this, think the server as a queue. The teacher sends a message on the queue (push). The client has a background thread to periodically checks the queue (pull). Take a look at RabbitMQ. This will suit your need using a concept known as topics. – code5 Apr 29 '13 at 02:53
0

I have written a WCF server hosted on Windows Service using net.tcp and it definitely can push data to multiple clients. The framework does much of the listening, accepting and multiple connections for you so there's definitely a lot of benefits to yield.

The tricky part in your scenario would be sharing data from the teach client with student client. AFAIK, there is no built-in way to transfer data from one client-server connection to another.

One naive but simple way is to store the teacher data to a temp location (like a file or database and have some kind of mutex lock on it) and when it is time to transfer data to student, just read from the temp location.

Or you can change your architecture into Peer-To-Peer.

Community
  • 1
  • 1
Jake
  • 11,273
  • 21
  • 90
  • 147