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.
To download this code sample, click the following link:
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:
Create and initialize SocketAsyncEventArgs class, write eventhandler and register it to SocketAsyncEventArgs's completed event.
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.
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:
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: