SocketOptionLevel
Enumeration
Specifies the level at which a socket option is set or retrieved.
Namespace:
System.Net.Sockets
Assembly:
System.Net.Sockets.dll
Syntax
public enum SocketOptionLevel
Remarks
The SocketOptionLevel
enumeration is used with the
Socket.SetSocketOption
and Socket.GetSocketOption
methods to specify the option level to which the option applies.
Socket options can be set at the socket level (Socket
)
or at the transport protocol level (e.g., IP, TCP, UDP).
Members
Member | Value | Description |
---|---|---|
Socket |
0 | Specifies socket-level options. |
IP |
10 | Specifies options for the Internet Protocol (IP) version 4. |
IPSec |
11 | Specifies options for IP Security (IPsec). |
IPv6 |
41 | Specifies options for the Internet Protocol (IP) version 6. |
Icmp |
127 | Specifies options for the Internet Control Message Protocol (ICMP). |
Tcp |
6 | Specifies options for the Transmission Control Protocol (TCP). |
Udp |
17 | Specifies options for the User Datagram Protocol (UDP). |
Example
// Set the KeepAlive option for a TCP socket.
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
sock.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.KeepAlive, true);
// Get the SendBufferSize option for a socket.
int sendBuffer = (int)sock.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendBuffer);
Console.WriteLine($"Send Buffer Size: {sendBuffer}");
See Also
Socket.SetSocketOption
MethodSocket.GetSocketOption
MethodSocketOptionName
EnumerationSocket
Class