There are two books that any TCP/IP network programmer needs to have. Unfortunately, they were both written well before .NET, so they only deal with unmanaged code - specifically, the WinSock API. However, the .NET Socket class methods directly correspond to WinSock function calls, so knowledge can be gleaned from these books and directly applied to managed code.
- TCP/IP Illustrated, Volume 1 (The Protocols), by Stevens. Make a copy of pg 241 (the TCP State Transition Diagram), which is one of the most important pages ever printed. A good understanding of Chapter 18 is also important. Note that volume 1 is the only one most people need; volumes 2 and 3 delve into details about implementing TCP/IP stacks and specific (and rare) application protocols. However, volume 2 does have on the inside front cover a copy of the TCP State Transition Diagram updated with timeout events, which is nice to have.
- Network Programming for Microsoft Windows, by Jones and Ohlund. Chapter 5 has an excellent overview of the various I/O models available, which helps socket programmers understand how the BCL code is using asynchronous calls under the hood. This entire book should be read by TCP/IP programmers.
Note that when reading the unmanaged socket documentation, there are some potentially confusing terms:
- The terms blocking and nonblocking do not mean the same as the terms synchronous and asynchronous. Nonblocking sockets were a special quasi-asynchronous socket mode that is maintained only for backwards compatibility. Most modern WinSock programs (including .NET programs) use blocking sockets.
- TCP is a byte stream, connection-oriented protocol. Ignore any remarks specifically for message-based or connectionless protocols; they do not apply to TCP sockets.
There is a command-line utility that comes with Windows named netstat which displays TCP/IP endpoints. Other useful tools from Microsoft (that are not built in to the OS) are TCPView (a GUI version of netstat), Process Explorer (which also displays TCP/IP endpoints for each process), and DbgView (which displays trace statements from the Debug and default TraceSource classes in realtime).