Export (0) Print
Expand All

SocketOptionName Enumeration

Defines configuration option names.

Namespace:  System.Net.Sockets
Assembly:  System (in System.dll)

public enum SocketOptionName

Member nameDescription
AcceptConnectionThe socket is listening.
AddMembershipAdd an IP group membership.
AddSourceMembershipJoin a source group.
BlockSourceBlock data from a source.
BroadcastPermit sending broadcast messages on the socket.
BsdUrgentUse urgent data as defined in RFC-1222. This option can be set only once; after it is set, it cannot be turned off.
ChecksumCoverageSet or get the UDP checksum coverage.
DebugRecord debugging information.
DontFragmentDo not fragment IP datagrams.
DontLingerClose the socket gracefully without lingering.
DontRouteDo not route; send the packet directly to the interface addresses.
DropMembershipDrop an IP group membership.
DropSourceMembershipDrop a source group.
ErrorGet the error status and clear.
ExclusiveAddressUseEnables a socket to be bound for exclusive access.
ExpeditedUse expedited data as defined in RFC-1222. This option can be set only once; after it is set, it cannot be turned off.
HeaderIncludedIndicates that the application provides the IP header for outgoing datagrams.
HopLimitSpecifies 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.
IPOptionsSpecifies the IP options to be inserted into outgoing datagrams.
IPProtectionLevelEnables 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.
IpTimeToLiveSet the IP header Time-to-Live field.
IPv6OnlyIndicates 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.
KeepAliveUse keep-alives.
LingerLinger on close if unsent data is present.
MaxConnectionsNot supported; will throw a SocketException if used.
MulticastInterfaceSet the interface for outgoing multicast packets.
MulticastLoopbackAn IP multicast loopback.
MulticastTimeToLiveAn IP multicast Time to Live.
NoChecksumSend UDP datagrams with checksum set to zero.
NoDelayDisables the Nagle algorithm for send coalescing.
OutOfBandInlineReceives out-of-band data in the normal data stream.
PacketInformationReturn information about received packets.
ReceiveBufferSpecifies the total per-socket buffer space reserved for receives. This is unrelated to the maximum message size or the size of a TCP window.
ReceiveLowWaterSpecifies the low water mark for Receive operations.
ReceiveTimeoutReceive a time-out. This option applies only to synchronous methods; it has no effect on asynchronous methods such as the BeginSend method.
ReuseAddressAllows the socket to be bound to an address that is already in use.
SendBufferSpecifies the total per-socket buffer space reserved for sends. This is unrelated to the maximum message size or the size of a TCP window.
SendLowWaterSpecifies the low water mark for Send operations.
SendTimeoutSend a time-out. This option applies only to synchronous methods; it has no effect on asynchronous methods such as the BeginSend method.
TypeGet the socket type.
TypeOfServiceChange the IP header type of the service field.
UnblockSourceUnblock a previously blocked source.
UpdateAcceptContextUpdates 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.
UpdateConnectContextUpdates 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.
UseLoopbackBypass hardware when possible.

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.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft