MSDN Archive Home
Help and FAQs
Networking Samples for .NET v4.0
All Resource Updates
Change History (all pages)
Socket Performance Technology Sample
This sample shows how to use enhancements in the System.Net.Sockets.Socket class to build a server application that use asynchronous network I/O to achieve the highest performance.
Sample Language Implementations
This sample is available in the following language implementations:
To build the sample using the Command Prompt
Open the Visual Studio 2010 Command Prompt window and navigate to the CS subdirectory under the AsyncSocketServer directory.
Type msbuild AsyncSocketServer.sln at the command line. This command will build both the AsyncSocketServer and AsyncSocketClient applications.
To build the sample using Visual Studio
Open Windows Explorer and navigate to the CS subdirectory under the AsyncSocketServer directory.
Double-click the icon for AsyncSocketServer.sln to open the file in Visual Studio.
In the Build menu, select Build Solution.
Both the AsyncSocketServer and AsyncSocketClient applications are built in the default \bin or \bin\Debug directory.
To run the sample
Navigate to the directory that contains the new executable files, using the Command Prompt window.
Type AsyncSocketServer.exe at the command line with appropriate command-line arguments to run the AsyncSocketServer application.
Type AsyncSocketClient.exe at the command line with appropriate command-line arguments to run the AsyncSocketClient application for testing the AsyncSocketServer application.
This sample requires the .NET Framework v4.0
The AsyncSocketServer application requires four command-line parameters.
AsyncSocketServer.exe <numConnections> <receiveSize > <addressFamily> <localPortNum>
The parameters are as follows:
numConnections - The maximum number of connections the server will accept simultaneously.
receiveSize - The buffer size, in bytes, used by the server for each receive operation.
addressFamily - The address family of the socket the server will use to listen for incoming connections. Supported values are ipv4 and ipv6.
localPortNum - The local port to which the server will bind.
An example usage to allow 500 connections on IPv4 with a 1024 byte buffer size for each receive operation and listen on port 8000 is as follows:
AsyncSocketServer.exe 500 1024 ipv4 8000
The AsyncSocketClient application requires two command-line parameters.
AsyncSocketClient.exe <destIPAddress> <destPortNum>
The parameters are as follows:
destIpaddress - The destination IP address of the AsyncSocketServer to connect to.
destPortNum - The destination port number of the AsyncSocketServer.
Nov 7 2009 at 12:51 AM
, version 4
Aug 15 2011 at 2:53 PM
If we do not want send echo back to client? how to start acceptiong ather packages?
Oct 22 2011 at 12:14 PM
What happens when we reach the maximum number of connections?
There is a memory leak on this sample, the memory usage is always rising, not getting down when clients disconnects.
Sign in to add a comment
.NET 4.0 Code Samples
Fri Nov 6 2009 at 8:00 AM
More Tags ...
Visual Studio 2005
Visual Studio 2008
Visual Studio 2010
Manage Your Profile
MSDN Flash Newsletter
© 2008 Microsoft Corporation. All rights reserved.