System.Net.Sockets.Socket.SetSocketOption Method

Sets the specified System.Net.Sockets.Socket option to the specified bool value.

Syntax

public void SetSocketOption (SocketOptionLevel optionLevel, SocketOptionName optionName, bool optionValue)

Parameters

optionLevel
One of the System.Net.Sockets.SocketOptionLevel values.
optionName
One of the System.Net.Sockets.SocketOptionName values.
optionValue
The value of the option, represented as a bool.

Remarks

System.Net.Sockets.Socket options determine the behavior of the current System.Net.Sockets.Socket. Set optionValue to true to enable the option, or to false to disable the option.

System.Net.Sockets.Socket options are grouped by level of protocol support.

Listed below are the various System.Net.Sockets.Socket options that can be set using this overload. These options are grouped by the appropriate System.Net.Sockets.SocketOptionLevel value. If you intend to set any of these options, be sure to use the appropriate System.Net.Sockets.SocketOptionLevel value for the optionLevel parameter. The option you choose to set must be specified in the optionName parameter. If you want to get the current value of any of the options listed, use the Socket.GetSocketOption(SocketOptionLevel, SocketOptionName) method.

SocketOptionLevel.Socket options that can be set using this overload.

SocketOptionLevel.IP options that can be set using this overload.

SocketOptionLevel.Tcp options that can be set using this overload.

SocketOptionLevel.Udp options that can be set using this overload.

For more information on these options, refer to the System.Net.Sockets.SocketOptionName enumeration.

Note:

If you receive a System.Net.Sockets.SocketException exception, use the SocketException.ErrorCode property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

Requirements

Namespace: System.Net.Sockets
Assembly: System (in System.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0