System.Net.Sockets Namespace

Provides classes for low-level network access using sockets.

Sockets

This namespace contains classes that enable low-level network communication. It provides access to the socket API, allowing developers to create and manage network connections using various protocols like TCP and UDP.

Socket

Represents a socket, which is an endpoint for sending and receiving data across a network.

Methods

  • ConnectEstablishes a connection to a remote host.
  • SendSends data to a connected socket.
  • ReceiveReceives data from a connected socket.
  • BindAssociates a local endpoint with the socket.
  • ListenBegins listening for incoming connections.
  • AcceptAccepts an incoming connection.
  • CloseReleases the socket.

Properties

  • LocalEndPointGets the local endpoint of the socket.
  • RemoteEndPointGets the remote endpoint of the socket.
  • AvailableGets the amount of data, in bytes, that can be read from the socket.
  • ProtocolTypeGets the network protocol type of the Socket.

IPAddress

Represents an Internet Protocol (IP) address.

Static Properties

  • IPv4LoopbackGets the loopback address.
  • IPv6LoopbackGets the IPv6 loopback address.
  • AnyGets an IP address that indicates that the server can receive requests from any available network interface.

Methods

  • Parse(string)Converts an IPv4 or IPv6 address string to an IPAddress instance.
  • ToString()Returns the string representation of the IP address.

SocketException

Represents an error that occurred when performing a blocking Socket call.

Properties

  • ErrorCodeGets the error code associated with the exception.

SocketFlags

Specifies the behavior of socket operations.

Members

  • NoneNo flags are set.
  • BroadcastEnable broadcast transmission.
  • MulticastEnable multicast transmission.
  • DontRouteDo not use a routing table.

SocketType

Specifies the type of socket.

Members

  • StreamA reliable, two-way, connection-based byte stream.
  • DgramA connectionless, unreliable datagram.
  • RawRaw socket access.
  • RdmA reliable, connection-based datagram.

ProtocolType

Specifies the network protocol type.

Members

  • IPInternet Protocol.
  • TCPTransmission Control Protocol.
  • UDPUser Datagram Protocol.
  • ICMPInternet Control Message Protocol.

AddressFamily

Specifies the address family for the socket.

Members

  • InterNetworkInternet Protocol version 4 (IPv4).
  • InterNetworkV6Internet Protocol version 6 (IPv6).
  • UnixUnix domain socket.

SocketAddress

Represents the socket address for a specific address family.

SocketSHost

Represents the DNS host information.

SocketSHostEntry

Stores host information such as the canonical name, aliases, and IP addresses.

SocketSHostName

Represents the hostname.

SocketSHostAddress

Represents an IP address associated with a host.