Socket Connection Limit Testing Utility

Mike Woodring
http://staff.develop.com/woodring

This sample demonstrates the use of asynchronous connection management and I/O operations using the .NET Socket classes. And since the client and server applications are Windows Forms applications, they also demonstrate how to safely update controls in multithreaded applications.

Besides serving as sample code, the only real purpose of the application is to test the upper limits of a given machine's ability to either accept or make socket-based connections. Since this is a resource-limited problem, each machine has a different ceiling.

Refer to the comments in client.cs and server.cs for more details.

Usage

  1. Run both programs (the order doesn't matter). You may run the client and server on the same or different machines.
  2. In the server, enter an unused port number (999 by default) and press the Start button. The server is now ready to accept incoming connections. Select or unselect the check box indicating whether or not the server should reverse the characters in any text that clients send.
  3. In the client, enter the host name and port number of the server instance to connect to.
  4. Enter the # of connections to make when the Connect button is pressed (100 by default).
  5. Press the Connect button to make the specified number of connections.
  6. Repeat the above 1 or 2 steps as desired to test the upper limit of this machine's ability to make connections and the specified server's ability to accept connections. Note that if you're running the client and server on the same machine, the upper limit will be less than what it will be if you run the client and server programs on separate machines. Also note that a single instance of the client program can connect to any number of server instances/machines. When text is sent from the client UI, the client program simply sends the text to the server that it last connected to.

Shutting Down

You may either press Stop on the server to reset the server to its initial startup state (causing any connected clients to detect the server has shutdown), or press Disconnect on the client to drop all connections to the server(s) (causing the associated server(s) to detect client disconnect).

Notes

The Most Recent Exception control displays the text and stack trace of the most recent exception each program has received that was expected due to some kind of communications failure. Other exceptions are not trapped and result in the typical unhandled exception dialog for Windows Forms programs - and indicate an actual error in the program that I didn't anticipate.