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.GetSocketOption Method

Returns the value of a Socket option.

Overload List

Returns the value of a specified Socket option, represented as an object.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function GetSocketOption(SocketOptionLevel, SocketOptionName) As Object
[C#] public object GetSocketOption(SocketOptionLevel, SocketOptionName);
[C++] public: Object* GetSocketOption(SocketOptionLevel, SocketOptionName);
[JScript] public function GetSocketOption(SocketOptionLevel, SocketOptionName) : Object;

Returns the specified Socket option setting, represented as a byte array.

Supported by the .NET Compact Framework.

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

Returns the value of the specified Socket option in an array.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function GetSocketOption(SocketOptionLevel, SocketOptionName, Integer) As Byte()
[C#] public byte[] GetSocketOption(SocketOptionLevel, SocketOptionName, int);
[C++] public: unsigned char GetSocketOption(SocketOptionLevel, SocketOptionName, int) __gc[];
[JScript] public function GetSocketOption(SocketOptionLevel, SocketOptionName, int) : Byte[];

Example

[Visual Basic, C#, C++] The following example retrieves the LingerOption and Send time-out values and displays them to the console.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of GetSocketOption. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Console.WriteLine(("This application will timeout if Send does not return within " + Encoding.ASCII.GetString(s.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 4))))
' blocks until send returns
Dim i As Integer = s.Send(msg)

' blocks until read returns
Dim bytes(1024) As Byte
s.Receive(bytes)

'Display to the screen
Console.WriteLine(Encoding.ASCII.GetString(bytes))
s.Shutdown(SocketShutdown.Both)

Console.WriteLine(("If data remains to be sent, this application will stay open for " + CType(s.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger), LingerOption).LingerTime.ToString()))
s.Close()
    End Sub 'SetSocketOptions

[C#] 
Console.WriteLine ("This application will timeout if Send does not return within " + Encoding.ASCII.GetString (s.GetSocketOption (SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 4)));

// blocks until send returns
int i = s.Send (msg);

// blocks until read returns
byte[] bytes = new byte[1024];

s.Receive (bytes);

//Display to the screen
Console.WriteLine (Encoding.ASCII.GetString (bytes));
s.Shutdown (SocketShutdown.Both);
Console.WriteLine ("If data remains to be sent, this application will stay open for " + ((LingerOption)s.GetSocketOption (SocketOptionLevel.Socket, SocketOptionName.Linger)).LingerTime.ToString ());
s.Close ();

[C++] 
Console::Write("This application will timeout if Send does not return within ");
Console::WriteLine(Encoding::ASCII->GetString(s->GetSocketOption(SocketOptionLevel::Socket, 
    SocketOptionName::SendTimeout, 4)));
// Blocks until send returns.
int i = s->Send(msg);

// Blocks until read returns.
Byte bytes[] = new Byte[1024];
s->Receive(bytes);

//Displays to the screen.
Console::WriteLine(Encoding::ASCII->GetString(bytes));
s->Shutdown(SocketShutdown::Both);

Console::Write("If data remains to be sent, this application will stay open for ");
Console::WriteLine(__box(__try_cast<LingerOption *> (s->GetSocketOption(SocketOptionLevel::Socket, 
    SocketOptionName::Linger))->LingerTime)->ToString());
s->Close();

[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:
© 2014 Microsoft