Partekatu bidez


Socket.GetSocketOption Método

Definición

Devuelve el valor de una Socket opción.

Sobrecargas

Nombre Description
GetSocketOption(SocketOptionLevel, SocketOptionName)

Devuelve el valor de una opción especificada Socket , representada como un objeto .

GetSocketOption(SocketOptionLevel, SocketOptionName, Byte[])

Devuelve la configuración de opción especificada Socket , representada como una matriz de bytes.

GetSocketOption(SocketOptionLevel, SocketOptionName, Int32)

Devuelve el valor de la opción especificada Socket en una matriz.

GetSocketOption(SocketOptionLevel, SocketOptionName)

Source:
Socket.cs
Source:
Socket.cs
Source:
Socket.cs
Source:
Socket.cs

Devuelve el valor de una opción especificada Socket , representada como un objeto .

public:
 System::Object ^ GetSocketOption(System::Net::Sockets::SocketOptionLevel optionLevel, System::Net::Sockets::SocketOptionName optionName);
public object? GetSocketOption(System.Net.Sockets.SocketOptionLevel optionLevel, System.Net.Sockets.SocketOptionName optionName);
public object GetSocketOption(System.Net.Sockets.SocketOptionLevel optionLevel, System.Net.Sockets.SocketOptionName optionName);
member this.GetSocketOption : System.Net.Sockets.SocketOptionLevel * System.Net.Sockets.SocketOptionName -> obj
Public Function GetSocketOption (optionLevel As SocketOptionLevel, optionName As SocketOptionName) As Object

Parámetros

optionLevel
SocketOptionLevel

Uno de los SocketOptionLevel valores.

optionName
SocketOptionName

Uno de los SocketOptionName valores.

Devoluciones

Objeto que representa el valor de la opción. Cuando el optionName parámetro se establece en Linger el valor devuelto es una instancia de la LingerOption clase . Cuando optionName se establece AddMembership en o DropMembership, el valor devuelto es una instancia de la MulticastOption clase . Cuando optionName es cualquier otro valor, el valor devuelto es un entero.

Excepciones

Error al intentar acceder al socket.

O bien:

optionName se estableció en el valor MaxConnectionsno admitido .

Ejemplos

En el ejemplo de código siguiente se recuperan los LingerOption valores y Send se agota el tiempo de espera y se muestran en la consola.

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();
    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

Comentarios

Socket las opciones determinan el comportamiento del objeto actual Socket. Use esta sobrecarga para obtener las Lingeropciones , AddMembershipy DropMembershipSocket . Para la Linger opción , use Socket para el optionLevel parámetro . Para AddMembership y DropMembership, use IP. Si desea establecer el valor de cualquiera de las opciones enumeradas anteriormente, use el SetSocketOption método .

Nota:

Si recibe un SocketException, use la SocketException.ErrorCode propiedad para obtener el código de error específico. Después de obtener este código, consulte la documentación del código de error de la API de Windows Sockets versión 2 para obtener una descripción detallada del error.

Nota:

Este miembro genera información de seguimiento al habilitar el seguimiento de red en la aplicación. Para obtener más información, consulte Seguimiento de red en .NET Framework.

Consulte también

Se aplica a

GetSocketOption(SocketOptionLevel, SocketOptionName, Byte[])

Source:
Socket.cs
Source:
Socket.cs
Source:
Socket.cs
Source:
Socket.cs

Devuelve la configuración de opción especificada Socket , representada como una matriz de bytes.

public:
 void GetSocketOption(System::Net::Sockets::SocketOptionLevel optionLevel, System::Net::Sockets::SocketOptionName optionName, cli::array <System::Byte> ^ optionValue);
public void GetSocketOption(System.Net.Sockets.SocketOptionLevel optionLevel, System.Net.Sockets.SocketOptionName optionName, byte[] optionValue);
member this.GetSocketOption : System.Net.Sockets.SocketOptionLevel * System.Net.Sockets.SocketOptionName * byte[] -> unit
Public Sub GetSocketOption (optionLevel As SocketOptionLevel, optionName As SocketOptionName, optionValue As Byte())

Parámetros

optionLevel
SocketOptionLevel

Uno de los SocketOptionLevel valores.

optionName
SocketOptionName

Uno de los SocketOptionName valores.

optionValue
Byte[]

Matriz de tipo Byte que va a recibir la configuración de opción.

Excepciones

Error al intentar acceder al socket.

O bien:

En las aplicaciones de .NET Compact Framework, el espacio de búfer predeterminado de Windows CE se establece en 32768 bytes. Puede cambiar el espacio de búfer por socket llamando a SetSocketOption.

Ejemplos

En el ejemplo de código siguiente se recuperan los LingerOption valores y Send se agota el tiempo de espera y se muestran en la consola.

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();
    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

Comentarios

Socket las opciones determinan el comportamiento del objeto actual Socket. Tras completar correctamente este método, la matriz especificada por el optionValue parámetro contiene el valor de la opción especificada Socket .

Cuando la longitud de la optionValue matriz es menor que el número de bytes necesarios para almacenar el valor de la opción especificada Socket , GetSocketOption se producirá una SocketExceptionexcepción . Si recibe un SocketException, use la SocketException.ErrorCode propiedad para obtener el código de error específico. Después de obtener este código, consulte la documentación del código de error de la API de Windows Sockets versión 2 para obtener una descripción detallada del error. Use esta sobrecarga para los sockets representados por valores booleanos o enteros.

Nota:

Este miembro genera información de seguimiento al habilitar el seguimiento de red en la aplicación. Para obtener más información, consulte Seguimiento de red en .NET Framework.

Consulte también

Se aplica a

GetSocketOption(SocketOptionLevel, SocketOptionName, Int32)

Source:
Socket.cs
Source:
Socket.cs
Source:
Socket.cs
Source:
Socket.cs

Devuelve el valor de la opción especificada Socket en una matriz.

public:
 cli::array <System::Byte> ^ GetSocketOption(System::Net::Sockets::SocketOptionLevel optionLevel, System::Net::Sockets::SocketOptionName optionName, int optionLength);
public byte[] GetSocketOption(System.Net.Sockets.SocketOptionLevel optionLevel, System.Net.Sockets.SocketOptionName optionName, int optionLength);
member this.GetSocketOption : System.Net.Sockets.SocketOptionLevel * System.Net.Sockets.SocketOptionName * int -> byte[]
Public Function GetSocketOption (optionLevel As SocketOptionLevel, optionName As SocketOptionName, optionLength As Integer) As Byte()

Parámetros

optionLevel
SocketOptionLevel

Uno de los SocketOptionLevel valores.

optionName
SocketOptionName

Uno de los SocketOptionName valores.

optionLength
Int32

Longitud, en bytes, del valor devuelto esperado.

Devoluciones

Byte[]

Matriz de tipo Byte que contiene el valor de la opción de socket.

Excepciones

Error al intentar acceder al socket.

O bien:

En las aplicaciones de .NET Compact Framework, el espacio de búfer predeterminado de Windows CE se establece en 32768 bytes. Puede cambiar el espacio de búfer por socket llamando a SetSocketOption.

Ejemplos

En el ejemplo de código siguiente se recuperan los LingerOption valores y Send se agota el tiempo de espera y se muestran en la consola.

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();
    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

Comentarios

El optionLength parámetro establece el tamaño máximo de la matriz de bytes devuelta. Si el valor de opción requiere menos bytes, la matriz solo contendrá ese número de bytes. Si el valor de la opción requiere más bytes, GetSocketOption producirá una SocketExceptionexcepción . Use esta sobrecarga para los sockets representados por valores booleanos o enteros.

Nota:

Si recibe un SocketException, use la SocketException.ErrorCode propiedad para obtener el código de error específico. Después de obtener este código, consulte la documentación del código de error de la API de Windows Sockets versión 2 para obtener una descripción detallada del error.

Nota:

Este miembro genera información de seguimiento al habilitar el seguimiento de red en la aplicación. Para obtener más información, consulte Seguimiento de red en .NET Framework.

Consulte también

Se aplica a