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 ...

Get C# Primer: A Practical Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.