During the last month, I have used the .NET 1.1 socket classes. I have got several problems with this API:
  • Some Bugs in this API
  • Some performance problems
To compare, Java as an API (nio) to handle sockets correctly and in an optimized manner. NET do not has this one yet and will not have it for .NET 1.1 (We must wait for WFC).

So, my goal is to provide a set of classes to handle sockets correctly and in a very optimized way. There are several way to play with socket:
  • by using"Select"
  • by using asynchronous call
  • by using threads
  • IOCP
"Select", "asynchronous" and "threads" are native in .NET but handle a maximum of 7500 connections (1500 for Select) approximatively. IOCP can handle up to 50000 connections approximatively, but are not well integrated with .NET 1.0 or 1.1 (and 2.0 ??)

So, it is well know that IOCP is the best method to manage sockets (For serveral reasons). I will not describe what is IOCP and how it work, but simply tell that IOCP detects socket events at the kernel level and IOCP provides the mechanism to associate a socket (i.e. completion port) with a user data pointer directly.

If you want more information about IOCP and socket, there are numerous articles on the web.

So, this article present the IOCP Thread class and a Socket Wrapper class to acheive high performance socket in C#.

There are 3 classes:
  • HiPerfSocketThreadPool
  • HiPerfSocket
  • HiPerfSocketStream
For advanced users : It is a very first version of my class. I do not use the IOCP thread as traditionaly but it sounds working. If someone want to improve it. He's welcome. I will post improved version during the classes evolution.

The HiPerfSocketThreadPool.cs class manage the IOCP calls.
I do not use the IOCP thread as traditionaly but it sounds working.

All theses classes have been tested and are working fine. But I m sure that we can find several way to improve this library. So, please, send me bug report and/or improved version of the classes and even new classes.

NB: All the files are attached in a ZIP file with this post.