How to use Socket in Microsoft Silverlight 3

Article ID: 2278179 - View products that this article applies to.
Expand all | Collapse all

On This Page

INTRODUCTION

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

Collapse this imageExpand this image
codefx Medium

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:

Network Security Access Restrictions in Silverlight

Note
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

Languages

This code sample contains the following programming languages:

Collapse this tableExpand this table
LanguageProject Name
Visual C#CSSL3Socket
Visual Basic.NETVBSL3Socket

Prerequisites

Tags

  • Socket, Silverlight

MORE INFORMATION

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:

http://1code.codeplex.com

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:

http://support.microsoft.com/gp/gp_kbcodefx


REFERENCES

For more information, visit the following Web sites:

Socket Class
Network Security Access Restrictions in Silverlight

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.

Properties

Article ID: 2278179 - Last Review: August 12, 2010 - Revision: 2.0
APPLIES TO
  • Microsoft Visual Studio 2008 Service Pack 1
Keywords: 
kbcodefx kbsurveynew kbinfo kbnomt atdownload kbrapidpub KB2278179

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com