System.Net.Sockets.Socket.SetSocketOption Method

Sets the specified System.Net.Sockets.Socket option to the specified value, represented as an object.

Syntax

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

Parameters

optionLevel
One of the System.Net.Sockets.SocketOptionLevel values.
optionName
One of the System.Net.Sockets.SocketOptionName values.
optionValue
A System.Net.Sockets.LingerOption or System.Net.Sockets.MulticastOption that contains the value of the option.

Exceptions

TypeReason
ArgumentException optionLevel, optionName, or optionValue specified an invalid value.
ArgumentNullException optionValue is null.
System.Net.Sockets.SocketException
Note: For additional information on causes of the SocketException, see the System.Net.Sockets.SocketException class.
System.Security.SecurityExceptionA caller in the call stack does not have the required permissions.
ObjectDisposedExceptionThe current instance has been disposed.

Remarks

System.Net.Sockets.Socket options determine the behavior of the current System.Net.Sockets.Socket. Use this overload to set the SocketOptionName.Linger, SocketOptionName.AddMembership, and SocketOptionName.DropMembership System.Net.Sockets.Socket options. For the SocketOptionName.Linger option, use System.Net.Sockets.Socket for the optionLevel parameter. For SocketOptionName.AddMembership and SocketOptionName.DropMembership, use SocketOptionLevel.IP. If you want to get the current value of any of the options listed above, use the Socket.GetSocketOption(SocketOptionLevel, SocketOptionName) method.

Note:

If you receive a System.Net.Sockets.SocketException, 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.

Permissions

Requirements

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