Sockets are the transport mechanism most frequently used in high-performance server applications. Fortunately, the Win32~® Windows~® Sockets library (Winsock) provides mechanisms to improve the performance of programs that use sockets, and the Microsoft~® .NET Framework provides a layer over Winsock so that managed applications can communicate over sockets (see Figure 1). So much advanced socket support is great, but using all these layers to write a truly high-performance socket-based application requires a little background information. I am going to write a trivial chat server app to explore methods for writing a socket-based server and client using the base Sys-tem.Net.Sockets.Socket class. Although .NET provides higher-level abstractions like the TcpListener and TcpClient classes (also in System.NetSockets), these classes are missing some of the advanced features exposed by the lower-level Socket class. That said, they can be useful in many situations. The TcpListener class provides simple methods that listen for and accept incoming connection requests in blocking synchronous mode, while the TcpClient class provides simple methods for connecting, sending, and receiving stream data over a network in synchronous blocking mode.
展开▼