5.9. System.Net.Sockets
The System.Net.Sockets namespace provides a Socket class encapsulating Windows Sockets functionality. Transmission Control Protocol (TCP) support is provided by the TcpListener and TcpClient classes. To illustrate how we can use these classes, we'll create a client/server phone directory from the sample Northwind SQL database. On separate threads, the server retrieves the database information and sets up a TcpListener object to accept incoming requests. The client creates a TcpClient object, acquires a NetworkStream object, and then packages and sends a request over the network. A client session is pictured in Figure 5.1. The port number of the client request is displayed in square brackets. The server line with the phone ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access