C# has two methods of network programming
a) TcpClient or TCPListener (which are higher level abstractions of the Socket class)
b) Socket (has more functionality than abstracted classes) – WinSock
Network Programming Strategies:
1) Threaded Server – using a pool of threads, and Accept(). This is good for a small number of connections and clients and does not scale well, because of construction/destruction of threads. Simplest model.
2) Select for Multiplexed I/O – Involves monitoring a list of connections for their state, and stripping away those that are un-readable, un-writable or with error; allowing those that remain to be used. Of course, the same problem results with a large pool of connections in the thousands, where there is thrashing in “checking” the state of the connections every so often.
3) Asynchronous Call Back – Asynchronous I/O callbacks handle incoming data and connections, thus no need to setup lists to monitor (Select()) or threads to manage (Accept()). Here threads that are pooled for the application are re-used when there is something ready for processing, and the call back method is called. When the callback method is complete, the thread is returned to the pool. Thus instead of a thread being using for an entire request, it is only used for a single operation.