System.Net.Sockets



System.Net.Sockets

Sometimes programmers need to work at an even lower level of abstraction than the WebRequest and WebResponse objects that live in the System.Net namespace, particularly when porting legacy code. One popular low-level interface is the Berkeley Sockets interface. The System.Net.Sockets interface provides a managed code connection to this subsystem. It uses a number of objects from the System.Net namespace.

The base object of the Socket subsystem is, naturally, the Socket. After creating and configuring the Socket to your liking, you read and write data to it using a Network- Stream object, which maps the System.IO.Stream interface onto the socket's network connection.

The LingerOption object contains information about whether the connection should linger after closing the socket, and if so, for how long. The MulticastOption object contains the collection of IP addresses to which to send multicast packets.

Figure lists a number of enumerations in the socket class for specifying various options.

Enumeration

Meaning

AddressFamily

Specifies the addressing scheme that an instance of the Socket class can use.

ProtocolType

Specifies the protocols that the Socket class supports.

SelectMode

Defines the polling modes for the Socket.Poll method.

SocketFlags

Provides constant values for socket messages.

SocketOptionLevel

Defines socket option levels for the Socket.SetSocketOption and Socket.GetSocketOption methods.

SocketOptionName

Defines socket option names for the Socket class.

SocketShutdown

Defines constants used by the Socket.Shutdown method.

SocketType

Specifies the type of socket an instance of the Socket class represents.


The System.Net.Sockets namespace contains one new exception class, named SocketException.