Click here to Skip to main content
15,881,559 members
Articles / Web Development / ASP.NET

Your First Step to the Silverlight Voice/Video Chatting Client/Server

Rate me:
Please Sign up or sign in to vote.
4.85/5 (44 votes)
15 Dec 2013CPOL5 min read 342K   22.6K   188   92
What you should to do to create your own Silverlight Voice/Video chatting system
SocketCoderDesktopPresenter

Introduction

Comparing with the Adobe Flash Player, Microsoft has provided the first step to support the live voice/video chatting through the web By Supports dealing with the Microphone and the Camera in Silverlight 4. Yes it was a great step but still not enough, there is more of a problem that is still unresolved, and as a programmer you have to rely on yourself to make your own programming solutions if you decided to go ahead with working on Silverlight techniques to create your own live voice/video chatting software. It can be summarized as follows:

  1. There isn't any Managed Library for coding/decoding the Video/Audio data for compression to be suitable to send it via the Internet, comparing with Adobe technologies it supports dealing with the H.263 and H.264 to compress the audio and Video on high resolution, unfortunately it's still not available in Silverlight4.
  2. There isn't any support for the real time transport protocols, such as RTP. Therefore you just have two options, either through using the transport protocol TCP or UDP, or to program your own real time transport protocol. Comparing with Adobe, it supports transport through a custom protocol for this purpose in the RTMP.
  3. There isn't any real streaming server For Live Video/Audio streaming directly from Silverlight to the Media Server and from the media server to Silverlight clients, so you only have two solutions. You have to either use Microsoft Windows Media Server or use the Smooth Streaming through IIS, and will thus be obliged to renounce Silverlight, because Silverlight does not support dealing with these servers for sending and the only solution is also to create your own server. Compared to Adobe, they have a great product which is The Flash Media Server that deals perfectly with the Flash player.

Background

In general, all Voice/Video Chatting Systems must go through these phases:

  1. Connecting with a camera and/or microphone and then returning the output as Binary Data, then converting it to Bytes to make it easier to deal for the next step.
  2. The data will be returned as a Raw Format, therefore its size would be too large so we need first to code it into a compressed format. For example, coding the captured image into a JPEG format as well as the voice data can turn into a Wave Format or compress it into any well-known audio compression format such as G.711 ,GSM, speex or any other format standard. Also we can integrate the video/voice together using a special standard such as H.263 or H.264. This step is the most important thing we would be doing, it simply will determine the bandwidth requirements of your chatting system.
  3. Sending the compressed data using one of both transport protocols TCP, UDP or RTP/UDP transport protocol and this step is also important as it depends on the importance of data quality that is transferred on the one hand and the importance of the transfer in Real Time on the other hand. The goal of any system is to transfer the data in real time and in the best quality as possible.
  4. Receiving the sent data through the Server has specific functions depending on what you want from the application, as an example in the chatting software. The received data on the server side should send it back to the connected clients in the chat room. Usually if the software is working on the internet and if the clients are behind a NAT, the Server should be on a Public IP. Fortunately the Socket in Silverlight supports this process without any problem as you will see in this article.
  5. The Client would receive the data as a compressed format, so we need to decode it first and then display it on an output device.

Using the Code

The above phases can be achieved in the following steps:

On the client side:

  1. To know how to access into the Microphone and the Camera, check this video.
  2. To Know how to decode the captured image into JPEG format, check this article and this one.
  3. To know how to record the voice from the microphone and then play it back into the speakers using the AudioSink and The MediaElement Classes in Silverlight. Check these articles:
    1. Record The Audio Into A Wave File
    2. Playback The Wave File in Silverlight
    3. Using the G.711 Codec
  4. To Know how to use the Socket in Silverlight, check this video and also a good video for Network Authentication and Trusted Network Access here.

On the server side:

In our case, the server should do the following processes:

  1. Allowing the clients to communicate with the server - to do this in Silverlight, you should create a policy service on the server side on port 943 to grant the clients access on the server domain. To achieve this, create an XML file that contains below to allow using the TCP port 4530 and the all domains URI on the server as an example:
    XML
    <?xml version="1.0" encoding ="utf-8"?> 
    <access-policy> 
    <cross-domain-access> 
    <policy> 
    <allow-from> 
    <domain uri="*" /> 
    </allow-from> 
    <grant-to> 
    <socket-resource port="4530" protocol="tcp" /> 
    </grant-to> 
    </policy> 
    </cross-domain-access> 
    </access-policy> 

    Then create a socket to grant access on port 943 as a default port for the policy service in Silverlight: (Please check the PolicyService.cs class that is attached with the article samples.)

  2. Receiving the Client request and adding the client socket to an Array List - after that, the server should receive the client data (Audio or Video data), then send it to all the connected clients using the Socket Array List that we created as an example. (Please Check the SocketCoderBinaryServer.cs class that is attached with the article samples.)

Finally

The client and the server should do more than this but as a starting point, this will be very useful to get you through the beginning of network programming in Silverlight to create your own client/server voice/video chatting system.

References

  1. SocketCoder.Com, to download the last update of the Silverlight 4 Web Conferencing Project:
    1. Module 1: Silverlight 4 Voice Chat Sample: http://socketcoder.com/ArticleFile.aspx?index=2&ArticleID=70
    2. Module 2: Silverlight 4 WebCam Conferencing Sample: http://socketcoder.com/ArticleFile.aspx?index=2&ArticleID=68
    3. Module 3: Silverlight 4 Desktop Presenter Sample: http://socketcoder.com/ArticleFile.aspx?index=2&ArticleID=69
  2. Silverlight.NET http://www.silverlight.net/
  3. Microsoft MSDN

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Systems Engineer SocketCoder.Com
Jordan Jordan
Fadi Abdelqader
WebSite: http://www.SocketCoder.com
Facebook Group: http://www.facebook.com/groups/socketcoder/
Facebook Page: http://www.facebook.com/socketcoders/

Last Published Book:
-Professional Network, Distributed Systems & TCP/IP Programming In .NET Framework 1.1 & 2.0 (2006 Release)

Last Published eBook:
- The SocketCoder e-Reference For Network, Distributed Systems And TCP/IP Programming In .NET, Arabic (SocketCoder.Com 2010)

Last Projects:
- Silverlight Based Projects For Web Video Conferencing (WCS,WMS,WCS Plus..)
-(SocketCoder) RTP Multicasting VOIP Library
-(SocketCoder) Remote Controlling Systems

Last SocketCoder RSS: http://www.socketcoder.com/feed/

http://www.socketcoder.com

Comments and Discussions

 
AnswerRe: video / audio compression Pin
Fadi Abdelqader21-Nov-10 2:14
Fadi Abdelqader21-Nov-10 2:14 
General1 client Pin
hamada el3ashe220-Nov-10 12:27
hamada el3ashe220-Nov-10 12:27 
AnswerRe: 1 client Pin
Fadi Abdelqader21-Nov-10 2:18
Fadi Abdelqader21-Nov-10 2:18 
GeneralRe: 1 client Pin
hamada el3ashe222-Nov-10 14:30
hamada el3ashe222-Nov-10 14:30 
GeneralRe: 1 client Pin
Fadi Abdelqader22-Nov-10 18:24
Fadi Abdelqader22-Nov-10 18:24 
GeneralRe: 1 client Pin
hamada el3ashe224-Nov-10 14:18
hamada el3ashe224-Nov-10 14:18 
QuestionCan this code be in Java?? Pin
Muthanna ABDULHUSSEIN16-Nov-10 12:19
Muthanna ABDULHUSSEIN16-Nov-10 12:19 
AnswerRe: Can this code be in Java?? Pin
Fadi Abdelqader21-Nov-10 2:22
Fadi Abdelqader21-Nov-10 2:22 
GeneralMy vote of 5 Pin
pravishrams11-Nov-10 0:26
pravishrams11-Nov-10 0:26 
GeneralTest Silverlight Web Conferencing System Online Pin
Fadi Abdelqader10-Nov-10 3:41
Fadi Abdelqader10-Nov-10 3:41 
GeneralRe: Test Silverlight Web Conferencing System Online Pin
hamada el3ashe231-Oct-10 3:52
hamada el3ashe231-Oct-10 3:52 
GeneralRe: Test Silverlight Web Conferencing System Online Pin
hamada el3ashe28-Nov-10 13:24
hamada el3ashe28-Nov-10 13:24 
GeneralRe: Test Silverlight Web Conferencing System Online Pin
Fadi Abdelqader8-Nov-10 19:23
Fadi Abdelqader8-Nov-10 19:23 
GeneralRe: Test Silverlight Web Conferencing System Online Pin
hamada el3ashe29-Nov-10 14:00
hamada el3ashe29-Nov-10 14:00 
GeneralRe: Test Silverlight Web Conferencing System Online Pin
Fadi Abdelqader9-Nov-10 19:03
Fadi Abdelqader9-Nov-10 19:03 
GeneralRe: Test Silverlight Web Conferencing System Online Pin
hamada el3ashe29-Nov-10 20:46
hamada el3ashe29-Nov-10 20:46 
GeneralRe: Test Silverlight Web Conferencing System Online Pin
Fadi Abdelqader10-Nov-10 3:50
Fadi Abdelqader10-Nov-10 3:50 
GeneralRe: Test Silverlight Web Conferencing System Online Pin
hamada el3ashe211-Nov-10 3:33
hamada el3ashe211-Nov-10 3:33 
GeneralRe: Test Silverlight Web Conferencing System Online Pin
Fadi Abdelqader11-Nov-10 4:04
Fadi Abdelqader11-Nov-10 4:04 
GeneralRe: Test Silverlight Web Conferencing System Online Pin
hamada el3ashe213-Nov-10 19:51
hamada el3ashe213-Nov-10 19:51 
GeneralAwesome! But compression... Pin
ToeStumper10-Jun-10 10:32
ToeStumper10-Jun-10 10:32 
GeneralRe: Awesome! But compression... Pin
superphil016-Jun-10 5:44
superphil016-Jun-10 5:44 
GeneralRe: Awesome! But compression... Pin
ToeStumper21-Jun-10 6:30
ToeStumper21-Jun-10 6:30 
GeneralQuery Pin
yaseen_12-Jun-10 8:03
yaseen_12-Jun-10 8:03 
GeneralRe: Query Pin
Fadi Abdelqader4-Jun-10 4:07
Fadi Abdelqader4-Jun-10 4:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.