Search Wiki:

Socket Performance Technology Sample

Download
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:
C#

To build the sample using the Command Prompt

  1. Open the Visual Studio 2010 Command Prompt window and navigate to the CS subdirectory under the AsyncSocketServer directory.
  2. 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

  1. Open Windows Explorer and navigate to the CS subdirectory under the AsyncSocketServer directory.
  2. Double-click the icon for AsyncSocketServer.sln to open the file in Visual Studio.
  3. 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

  1. Navigate to the directory that contains the new executable files, using the Command Prompt window.
  2. Type AsyncSocketServer.exe at the command line with appropriate command-line arguments to run the AsyncSocketServer application.
  3. Type AsyncSocketClient.exe at the command line with appropriate command-line arguments to run the AsyncSocketClient application for testing the AsyncSocketServer application.

Requirements

This sample requires the .NET Framework v4.0

Remarks

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.
Last edited Nov 7 2009 at 12:51 AM  by jetucker, version 4
Comments
LOV wrote  Aug 15 2011 at 2:53 PM  
If we do not want send echo back to client? how to start acceptiong ather packages?

AkiraShoji wrote  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.

Updating...
Page view tracker