Export (0) Print
Expand All

Socket Performance Technology Sample

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

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.

For information about using the samples, see the following topics:

To build the sample using the Command Prompt

  1. Open the Command Prompt window and navigate to the CS subdirectory under the AsyncSocketServer directory. For information about required settings and the SDK Command Prompt, see How to: Set Sample Settings.

  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.

This sample requires the .NET Framework v3.5, 3.0 SP1, or 2.0 SP1.

A series of new classes have been added as part of a set of enhancements to the System.Net.Sockets.Socket class that provides an alternative asynchronous pattern that can be used by specialized high-performance socket applications. These enhancements were specifically designed for network server applications that require high performance. An application can use the enhanced asynchronous pattern exclusively or only in targeted areas of their application (for example, when receiving large amounts of data).

The AsyncSocketServer sample demonstrates how to use these new methods on the System.Net.Sockets.Socket class by implementing an echo server. The server sends all the data read from a client back to the client. The echo server implemented in this sample handles multiple clients simultaneously (up to the maximum number specified as a command-line argument) and highlights some of the key elements of the event-based asynchronous socket methods. The AsyncSocketServer sample illustrates creating a pool of reusable data buffers and System.Net.Sockets.SocketAsyncEventArgs context objects as a method to increase server performance.

The AsyncSocketClient sample is a simple client application to use for testing the AsyncSocketServer sample application. The AsyncSocketClient sample does not use any of the new enhancements to the System.Net.Sockets.Socket class.

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.

© 2015 Microsoft