Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As the comment on your question says, UDP or other streaming protocols are usually preferred. But with WCF providing more abstraction, would be easier to do something like this. Having said that I have implemented a voice chatting feature on one of our previous software (the software was used by multiple clients in a LAN) with WCF and <code>netTcpBinding</code>, and it worked well (I tested it with 5 clients in a LAN), you couldn't really feel that WCF hindered the architecture. It will get interesting with the release of WCF 4.5 which will be supporting UDP transport.</p> <p>For something like this, you should really get the gist of duplex communication in WCF. I went about with doing in such a way that i had a <code>SendVoice()</code> operation contract on my service, everytime a client sent their asudio stream to the service, the <code>SendVoice()</code> method would iterate through the list of subscribers (connected clients) and invoke the <code>SendVoiceCallback()</code> on each client. You could start with something like this:</p> <pre><code>public void SendVoice(byte[] audio) { //Keep a list of connected clients in a dictionary called subscribers //lock your subscribers list so that it's not modified when you're in the middle of sending the stream lock (subscribers) { //send the received voice stream to each client foreach (var _subscriber in subscribers) { if (OperationContext.Current.GetCallbackChannel&lt;IVoiceChatCallback&gt;() == subscriber.Key) { //if the person who sent the video is the current subscriber then don't send the video to THAT subscriber continue; } try { //Send the received stream to the client asynchronously _subscriber.Key.BeginOnVoiceSendCallback(audio, onNotifyCompletedVoiceSend, _subscriber.Key); } catch (Exception) { //fault handling } } } } </code></pre> <p>Your clients would then call the method above periodically, in my implementation I set this to every 250 milliseconds and it worked perfectly well (obviously there was a small lag). </p> <p>In the code above <code>IVoiceChatCallback</code> is the callback contract. Callbacks enable the service to invoke some operation on the clients, so for an isntance the client will behave like a server. Asynchronous service calls will mean that your <code>SendVoice()</code> will publish the audio to every client asynchronously, rather than waiting for the previous stream to reach the client before sending the new stream.</p> <p>The code above is just an idea for you to get started. You should add some fault handling code to the service to check when clients are disconnected and remove them from your subscribers dictionary. Again You should become comfortable with asynchronous operation calls in WCF as well as callbacks. Also if you're looking to use this in LAN, then <code>netTcpBinding</code> is the way to go, and you should configure your service as to optimise its throughput and concurrency. Over the internet, you'd want to use a Http Binding that supports duplex.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload