How to use Socket in Microsoft Silverlight 3

This article has been archived. It is offered "as is" and will no longer be updated.
This article describes an All-In-One Code Framework sample that is available for download. Silverlight provides Socket API which gives the great flexibility for Silverlight network programming. This article describes the usage difference between Silverlight Socket and .Net Socket. This code sample demonstrates how to write Visual C#, or Visual Basic.NET code to perform Socket in Silverlight to communicate with socket server.

Difficulty level

Download information

To download this code sample, click the following link:


Technical overview

For performance consideration, unlike .Net Socket class, Silverlight Socket class only support asynchronous pattern method. To perform an asynchronous call, the typical processes are as in the following section:

  1. Create and initialize SocketAsyncEventArgs class, write eventhandler and register it to SocketAsyncEventArgs's completed event.
  2. Call Socket asynchronous method by using the SocketAsyncEventArgs class as parameter. If method returns False, the socket action returns result synchronously. If method returns True, the socket action returns result by SocketAsyncEventArgs.Completed event.
  3. When socket action returns result, SocketClient class checks the SocketAsyncEventArgs class and handles the result.
Because of security consideration, in Silverlight3, before Silverlight socket connects to a socket server, it will connect to server 943 port to obtain cross domain policy file and determine whether access is permitted. Therefore, to make socket server compatible with Silverlight socket client, socket server has to listen at 943 port, and establish connection to client and reply policy request with server network policy file.

For more information about network security access restrictions in Silverlight, please visit the following website:

For more information about how to create the sample application and how to deploy the sample application, see the Readme.txt file that is included in the download package.

Technology category

  • Silverlight


This code sample contains the following programming languages:

LanguageProject Name
Visual C#CSSL3Socket
Visual Basic.NETVBSL3Socket



  • Socket, Silverlight


What is All-In-One Code Framework?

All-In-One Code Framework shows most Microsoft development techniques by using code samples in different programming languages. Each example is carefully selected, composed, and documented to show one common code scenario. For more information about All-In-One Code Framework, visit the following Web site:

How to find more All-In-One Code Framework samples

To find more All-In-One Code Framework samples, you can simply click the following link:

For more information, visit the following Web sites:

Note This is a "FAST PUBLISH" article created directly from within the Microsoft support organization. The information contained herein is provided as-is in response to emerging issues. As a result of the speed in making it available, the materials may include typographical errors and may be revised at any time without notice. See Terms of Use for other considerations.

Article ID: 2278179 - Last Review: 12/12/2015 09:37:59 - Revision: 2.0

Microsoft Visual Studio 2008 Service Pack 1

  • kbnosurvey kbarchive kbcodefx kbsurveynew kbinfo kbnomt atdownload kbrapidpub KB2278179