As stated in the commentary on your question, UDP or other streaming protocols are usually preferred. But with WCF providing a lot of abstraction, it would be easier to do something like this. Having said that I implemented the voice chat feature on one of our previous programs (the software was used by several clients on the local network) with WCF and netTcpBinding , and it worked well (I tested it with 5 clients on the local network), you couldn’t feel that WCF is an obstacle to architecture. This will be interesting with the release of WCF 4.5, which will support UDP transport.
For something like this, you really should get the duplex entity in WCF. I continued to make it so that I had a contract for SendVoice() on my service, every time a client sent their asudio stream to a service, the SendVoice() method SendVoice() over the list of subscribers (connected clients) and call SendVoiceCallback() to every customer. You can start with something like this:
public void SendVoice(byte[] audio) {
Then your clients periodically called the method above, in my implementation I installed this every 250 milliseconds, and it worked fine (obviously, there was a slight lag).
The IVoiceChatCallback code IVoiceChatCallback has a callback contract. Callbacks allow the service to invoke some operation on clients, so for ISntance, the client will behave like a server. Asynchronous service calls mean that your SendVoice() will publish audio for each client asynchronously, rather than waiting for the previous thread to reach the client before sending a new thread.
The above code is just an idea for you to get started. You must add an error handling code to the service to check if clients are disconnected and remove them from your subscribers dictionary. Again, you should get comfortable with asynchronous calls in WCF, as well as with callbacks. Also, if you want to use this on a local network, then netTcpBinding is the way to go, and you must configure your service to optimize its bandwidth and concurrency. Over the Internet, you want to use Http bindings that support duplex.
Mohammad Sepahvand
source share