1 out of 2 rated this helpful - Rate this topic

SocketOptionName Enumeration

Defines configuration option names.

Namespace:  System.Net.Sockets
Assembly:  System (in System.dll)
public enum SocketOptionName
Member name Description
Debug Record debugging information.
AcceptConnection The socket is listening.
ReuseAddress Allows the socket to be bound to an address that is already in use.
KeepAlive Use keep-alives.
DontRoute Do not route; send the packet directly to the interface addresses.
Broadcast Permit sending broadcast messages on the socket.
UseLoopback Bypass hardware when possible.
Linger Linger on close if unsent data is present.
OutOfBandInline Receives out-of-band data in the normal data stream.
DontLinger Close the socket gracefully without lingering.
ExclusiveAddressUse Enables a socket to be bound for exclusive access.
SendBuffer Specifies the total per-socket buffer space reserved for sends. This is unrelated to the maximum message size or the size of a TCP window.
ReceiveBuffer Specifies the total per-socket buffer space reserved for receives. This is unrelated to the maximum message size or the size of a TCP window.
SendLowWater Specifies the low water mark for Send operations.
ReceiveLowWater Specifies the low water mark for Receive operations.
SendTimeout Send a time-out. This option applies only to synchronous methods; it has no effect on asynchronous methods such as the BeginSend method.
ReceiveTimeout Receive a time-out. This option applies only to synchronous methods; it has no effect on asynchronous methods such as the BeginSend method.
Error Get the error status and clear.
Type Get the socket type.
MaxConnections Not supported; will throw a SocketException if used.
IPOptions Specifies the IP options to be inserted into outgoing datagrams.
HeaderIncluded Indicates that the application provides the IP header for outgoing datagrams.
TypeOfService Change the IP header type of the service field.
IpTimeToLive Set the IP header Time-to-Live field.
MulticastInterface Set the interface for outgoing multicast packets.
MulticastTimeToLive An IP multicast Time to Live.
MulticastLoopback An IP multicast loopback.
AddMembership Add an IP group membership.
DropMembership Drop an IP group membership.
DontFragment Do not fragment IP datagrams.
AddSourceMembership Join a source group.
DropSourceMembership Drop a source group.
BlockSource Block data from a source.
UnblockSource Unblock a previously blocked source.
PacketInformation Return information about received packets.
HopLimit Specifies the maximum number of router hops for an Internet Protocol version 6 (IPv6) packet. This is similar to Time to Live (TTL) for Internet Protocol version 4.
IPProtectionLevel Enables restriction of a IPv6 socket to a specified scope, such as addresses with the same link local or site local prefix.This socket option enables applications to place access restrictions on IPv6 sockets. Such restrictions enable an application running on a private LAN to simply and robustly harden itself against external attacks. This socket option widens or narrows the scope of a listening socket, enabling unrestricted access from public and private users when appropriate, or restricting access only to the same site, as required. This socket option has defined protection levels specified in the IPProtectionLevel enumeration.
IPv6Only Indicates if a socket created for the AF_INET6 address family is restricted to IPv6 communications only. Sockets created for the AF_INET6 address family may be used for both IPv6 and IPv4 communications. Some applications may want to restrict their use of a socket created for the AF_INET6 address family to IPv6 communications only. When this value is non-zero (the default on Windows), a socket created for the AF_INET6 address family can be used to send and receive IPv6 packets only. When this value is zero, a socket created for the AF_INET6 address family can be used to send and receive packets to and from an IPv6 address or an IPv4 address. Note that the ability to interact with an IPv4 address requires the use of IPv4 mapped addresses. This socket option is supported on Windows Vista or later.
NoDelay Disables the Nagle algorithm for send coalescing.
BsdUrgent Use urgent data as defined in RFC-1222. This option can be set only once; after it is set, it cannot be turned off.
Expedited Use expedited data as defined in RFC-1222. This option can be set only once; after it is set, it cannot be turned off.
NoChecksum Send UDP datagrams with checksum set to zero.
ChecksumCoverage Set or get the UDP checksum coverage.
UpdateAcceptContext Updates an accepted socket's properties by using those of an existing socket. This is equivalent to using the Winsock2 SO_UPDATE_ACCEPT_CONTEXT socket option and is supported only on connection-oriented sockets.
UpdateConnectContext Updates a connected socket's properties by using those of an existing socket. This is equivalent to using the Winsock2 SO_UPDATE_CONNECT_CONTEXT socket option and is supported only on connection-oriented sockets.

The SocketOptionName enumeration defines the name of each Socket configuration option. Sockets can be configured with the Socket.SetSocketOption method.

The following code example uses this enumeration to set socket options.


        // Send operations will time-out if confirmation 
        // is not received within 1000 milliseconds.
        s.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 1000);

        // The socket will linger for 10 seconds after Socket.Close is called.
        LingerOption lingerOption = new LingerOption (true, 10);

        s.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.Linger, lingerOption);



.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
What type must the option value supplied be?

How am I to know what type the to supply the optionValue parameter when using Socket.SetSocketOption()??

For example should I supply a bool or int when trying to set NoDelay?:

msSock.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, true);
What about "Linger vs. DontLinger"?
What about "Linger vs. DontLinger"?
Typo
RFC-1222 is mentioned a few times, put it should read RFC-1122.