Namespace Overview
The System.Net namespace is the foundation for network communication in the .NET Framework. It provides a rich set of classes that enable developers to build a wide variety of network-aware applications, from simple client-server communication to complex web services.
Key functionalities include:
- Working with IP addresses and network endpoints.
- Making HTTP requests and handling responses.
- Managing network protocols like TCP and UDP.
- Resolving domain names to IP addresses.
- Handling network authentication and security.
This namespace contains classes for both low-level network socket programming and higher-level abstractions for common network tasks.
Classes
Type Definitions
Class IPAddress
public abstract class IPAddress
This class provides methods for manipulating IP addresses, including IPv4 and IPv6 representations.
Members:
Parse(string ipString): Static method to parse a string into an IP address.AddressFamily: Property indicating the IP address family (IPv4 or IPv6).IsIPv4MappedToIPv6: Property indicating if the address is an IPv4-mapped IPv6 address.
Class IPEndPoint
public sealed class IPEndPoint : EndPoint
Used to represent a network address for sockets.
Members:
IPEndPoint(IPAddress address, int port): Constructor.Address: Gets or sets the IP address of the endpoint.Port: Gets or sets the port number of the endpoint.
Class Uri
public abstract class Uri
Provides a way to work with URIs in a standardized manner.
Members:
Uri(string uriString): Constructor.Scheme: Gets the scheme component of the URI.Host: Gets the host component of the URI.Port: Gets the port number of the URI.
Class HttpClient
public class HttpClient : IDisposable
This is the primary class for making HTTP requests in modern .NET. It supports asynchronous operations for better performance.
Members:
GetAsync(string requestUri): Asynchronously sends a GET request.PostAsync(string requestUri, HttpContent content): Asynchronously sends a POST request.PutAsync(string requestUri, HttpContent content): Asynchronously sends a PUT request.DeleteAsync(string requestUri): Asynchronously sends a DELETE request.
Class TcpClient
public class TcpClient : IDisposable
A simplified interface for using TCP/IP sockets.
Members:
TcpClient(): Constructor.Connect(string hostname, int port): Connects to a remote TCP device.GetStream(): Gets the underlying network stream.
Class UdpClient
public class UdpClient : IDisposable
Allows sending and receiving UDP datagrams.
Members:
UdpClient(): Constructor.Send(byte[] datagram, int bytes, IPEndPoint endPoint): Sends UDP data.Receive(ref IPEndPoint remoteEP): Receives UDP data.
Class Dns
public static class Dns
A utility class for performing DNS lookups.
Members:
GetHostEntry(string hostNameOrAddress): Resolves a host name or IP address to an IPHostEntry object.GetHostAddresses(string hostName): Gets the IP addresses for the specified host.
Class NetworkCredential
public class NetworkCredential
Used for authentication purposes in network operations.
Members:
NetworkCredential(string userName, string password): Constructor.UserName: Gets the user's name.Password: Gets the user's password.