Chapter 16. Networking
.NET offers a variety of classes in the System.Net.*
namespaces for communicating via standard network protocols, such as HTTP and TCP/IP. Here’s a summary of the key components:
HttpClient
for consuming HTTP web APIs and RESTful servicesHttpListener
for writing an HTTP serverSmtpClient
for constructing and sending mail messages via SMTPDns
for converting between domain names and addressesTcpClient
,UdpClient
,TcpListener
, andSocket
classes for direct access to the transport and network layers
The .NET types in this chapter are in the System.Net.*
and System.IO
namespaces.
Note
.NET also provides client-side support for FTP, but only through classes that have been marked as obsolete from .NET 6. If you need to use FTP, your best option is to reach for a NuGet library such as FluentFTP.
Network Architecture
Figure 16-1 illustrates the .NET networking types and the communication layers in which they reside. Most types reside in the transport layer or application layer. The transport layer defines basic protocols for sending and receiving bytes (TCP and UDP); the application layer defines higher-level protocols designed for specific applications such as retrieving web pages (HTTP), sending mail (SMTP), and converting between domain names and IP addresses (DNS).
It’s usually most convenient to program at the application ...
Get C# 12 in a Nutshell 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.