Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Socket.SetSocketOption Method

Sets a Socket option.

Overload List

Sets the specified Socket option to the specified value, represented as a byte array.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Sub SetSocketOption(SocketOptionLevel, SocketOptionName, Byte())
[C#] public void SetSocketOption(SocketOptionLevel, SocketOptionName, byte[]);
[C++] public: void SetSocketOption(SocketOptionLevel, SocketOptionName, unsigned char __gc[]);
[JScript] public function SetSocketOption(SocketOptionLevel, SocketOptionName, Byte[]);

Sets the specified Socket option to the specified integer value.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Sub SetSocketOption(SocketOptionLevel, SocketOptionName, Integer)
[C#] public void SetSocketOption(SocketOptionLevel, SocketOptionName, int);
[C++] public: void SetSocketOption(SocketOptionLevel, SocketOptionName, int);
[JScript] public function SetSocketOption(SocketOptionLevel, SocketOptionName, int);

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

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Sub SetSocketOption(SocketOptionLevel, SocketOptionName, Object)
[C#] public void SetSocketOption(SocketOptionLevel, SocketOptionName, object);
[C++] public: void SetSocketOption(SocketOptionLevel, SocketOptionName, Object*);
[JScript] public function SetSocketOption(SocketOptionLevel, SocketOptionName, Object);

Example

[Visual Basic, C#, C++] The following example sets the LingerOption and Send time out values.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of SetSocketOption. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
'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.
Dim lingerOption As New LingerOption(True, 10)
s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, lingerOption)


[C#] 
// 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);


[C++] 
// Specifies that send operations will time-out 
// if confirmation is not received within 1000 milliseconds.
s->SetSocketOption(SocketOptionLevel::Socket, SocketOptionName::SendTimeout, 1000);

// Specifies that the Socket will linger for 10 seconds after Close is called.
LingerOption *lingerOption = new LingerOption(true, 10);
s->SetSocketOption(SocketOptionLevel::Socket, SocketOptionName::Linger, lingerOption);

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

Socket Class | Socket Members | System.Net.Sockets Namespace

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft