Socket.SetSocketOption Método

Definición

Establece una opción de Socket.

Sobrecargas

SetSocketOption(SocketOptionLevel, SocketOptionName, Boolean)

Establece la opción de Socket especificada en el valor de Boolean indicado.

SetSocketOption(SocketOptionLevel, SocketOptionName, Byte[])

Establece la opción de Socket indicada en el valor especificado, representado como una matriz de bytes.

SetSocketOption(SocketOptionLevel, SocketOptionName, Int32)

Establece la opción de Socket especificada en el valor entero indicado.

SetSocketOption(SocketOptionLevel, SocketOptionName, Object)

Establece la opción de Socket indicada en el valor especificado, representado como un objeto.

SetSocketOption(SocketOptionLevel, SocketOptionName, Boolean)

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

Establece la opción de Socket especificada en el valor de Boolean indicado.

public:
 void SetSocketOption(System::Net::Sockets::SocketOptionLevel optionLevel, System::Net::Sockets::SocketOptionName optionName, bool optionValue);
public void SetSocketOption (System.Net.Sockets.SocketOptionLevel optionLevel, System.Net.Sockets.SocketOptionName optionName, bool optionValue);
member this.SetSocketOption : System.Net.Sockets.SocketOptionLevel * System.Net.Sockets.SocketOptionName * bool -> unit
Public Sub SetSocketOption (optionLevel As SocketOptionLevel, optionName As SocketOptionName, optionValue As Boolean)

Parámetros

optionLevel
SocketOptionLevel

Uno de los valores de SocketOptionLevel.

optionName
SocketOptionName

Uno de los valores de SocketOptionName.

optionValue
Boolean

Valor de la opción, representado como Boolean.

Excepciones

El objeto Socket se ha cerrado.

Error al intentar acceder al socket.

Ejemplos

En el ejemplo de código siguiente se abre un socket y se habilitan OutOfBandInline las DontLinger opciones de socket y .

// Establish the local endpoint for the socket.
IPHostEntry^ ipHost = Dns::GetHostEntry( Dns::GetHostName() );
IPAddress^ ipAddr = ipHost->AddressList[ 0 ];
IPEndPoint^ ipEndPoint = gcnew IPEndPoint( ipAddr,11000 );

// Create a TCP socket.
Socket^ client = gcnew Socket( AddressFamily::InterNetwork,SocketType::Stream,ProtocolType::Tcp );

// Connect the socket to the remote endpoint.
client->Connect( ipEndPoint );

// Set option that allows socket to close gracefully without lingering.
client->SetSocketOption( SocketOptionLevel::Socket, SocketOptionName::DontLinger, true );

// Set option that allows socket to receive out-of-band information in the data stream.
client->SetSocketOption( SocketOptionLevel::Socket, SocketOptionName::OutOfBandInline, true );
// Establish the local endpoint for the socket.
IPHostEntry ipHost = Dns.GetHostEntry(Dns.GetHostName());
IPAddress  ipAddr = ipHost.AddressList[0];
IPEndPoint ipEndPoint = new IPEndPoint(ipAddr, 11000);

// Create a TCP socket.
Socket client = new Socket(AddressFamily.InterNetwork,
    SocketType.Stream, ProtocolType.Tcp);

// Connect the socket to the remote endpoint.
client.Connect(ipEndPoint);

// Set option that allows socket to close gracefully without lingering.
client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.DontLinger, true);

// Set option that allows socket to receive out-of-band information in the data stream.
client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.OutOfBandInline, true);

Comentarios

Socket las opciones determinan el comportamiento del objeto actual Socket. Establézcalo optionValue en true para habilitar la opción o para false deshabilitarla.

Socket Las opciones se agrupan por nivel de compatibilidad con protocolos.

A continuación se muestran las distintas Socket opciones que se pueden establecer con esta sobrecarga. Estas opciones se agrupan por el valor adecuado SocketOptionLevel . Si tiene previsto establecer cualquiera de estas opciones, asegúrese de usar el valor adecuado SocketOptionLevel para el optionLevel parámetro . La opción que elija establecer debe especificarse en el optionName parámetro . Si desea obtener el valor actual de cualquiera de las opciones enumeradas, use el GetSocketOption método .

SocketOptionLevel.Socket opciones que se pueden establecer mediante esta sobrecarga.

SocketOptionLevel.IP opciones que se pueden establecer mediante esta sobrecarga.

SocketOptionLevel.Tcp opciones que se pueden establecer mediante esta sobrecarga.

SocketOptionLevel.Udp opciones que se pueden establecer mediante esta sobrecarga.

Para obtener más información sobre estas opciones, consulte la SocketOptionName enumeración .

Nota:

Si recibe una SocketException excepción, 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.

Se aplica a

SetSocketOption(SocketOptionLevel, SocketOptionName, Byte[])

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

Establece la opción de Socket indicada en el valor especificado, representado como una matriz de bytes.

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

Parámetros

optionLevel
SocketOptionLevel

Uno de los valores de SocketOptionLevel.

optionName
SocketOptionName

Uno de los valores de SocketOptionName.

optionValue
Byte[]

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

Excepciones

Error al intentar acceder al socket.

El Socket se ha cerrado.

Ejemplos

En el ejemplo de código siguiente se establecen los LingerOption valores de tiempo de espera y Send .

// Specifies that the Socket will linger for 10 seconds after Close is called.
LingerOption^ lingerOption = gcnew LingerOption(true, 10);
s->SetSocketOption(SocketOptionLevel::Socket, SocketOptionName::Linger, lingerOption);
// The socket will linger for 10 seconds after Socket.Close is called.
var lingerOption = new LingerOption(true, 10);
s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, lingerOption);
' 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)

Comentarios

Socket las opciones determinan el comportamiento del objeto actual Socket. Use esta sobrecarga para establecer esas Socket opciones que requieren una matriz de bytes como un valor de opción.

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 cuando se habilita 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

SetSocketOption(SocketOptionLevel, SocketOptionName, Int32)

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

Establece la opción de Socket especificada en el valor entero indicado.

public:
 void SetSocketOption(System::Net::Sockets::SocketOptionLevel optionLevel, System::Net::Sockets::SocketOptionName optionName, int optionValue);
public void SetSocketOption (System.Net.Sockets.SocketOptionLevel optionLevel, System.Net.Sockets.SocketOptionName optionName, int optionValue);
member this.SetSocketOption : System.Net.Sockets.SocketOptionLevel * System.Net.Sockets.SocketOptionName * int -> unit
Public Sub SetSocketOption (optionLevel As SocketOptionLevel, optionName As SocketOptionName, optionValue As Integer)

Parámetros

optionLevel
SocketOptionLevel

Uno de los valores de SocketOptionLevel.

optionName
SocketOptionName

Uno de los valores de SocketOptionName.

optionValue
Int32

Valor de la opción.

Excepciones

Error al intentar acceder al socket.

El Socket se ha cerrado.

Ejemplos

En el ejemplo de código siguiente se establecen los LingerOption valores de tiempo de espera y Send .

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

Comentarios

Socket las opciones determinan el comportamiento del objeto actual Socket. Para una opción con un Boolean tipo de datos, especifique un valor distinto de cero para habilitar la opción y un valor cero para deshabilitar la opción. Para una opción con un tipo de datos entero, especifique el valor adecuado. Socket Las opciones se agrupan por nivel de compatibilidad con protocolos.

A continuación se muestran las distintas Socket opciones que se pueden establecer con esta sobrecarga. Estas opciones se agrupan mediante el adecuado SocketOptionLevel. Si tiene previsto establecer cualquiera de estas opciones, asegúrese de usar el adecuado SocketOptionLevel para el optionLevel parámetro . La opción que elija establecer debe especificarse en el optionName parámetro . Si desea obtener el valor actual de cualquiera de las opciones enumeradas, use el GetSocketOption método .

SocketOptionLevel.Socket opciones que se pueden establecer mediante esta sobrecarga.

SocketOptionLevel.IP opciones que se pueden establecer mediante esta sobrecarga.

SocketOptionLevel.Tcp opciones que se pueden establecer mediante esta sobrecarga.

SocketOptionLevel.Udp opciones que se pueden establecer mediante esta sobrecarga.

SocketOptionLevel.IPv6 opciones que se pueden establecer mediante esta sobrecarga.

Para obtener más información sobre estas opciones, consulte la SocketOptionName enumeración .

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 cuando se habilita 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

SetSocketOption(SocketOptionLevel, SocketOptionName, Object)

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

Establece la opción de Socket indicada en el valor especificado, representado como un objeto.

public:
 void SetSocketOption(System::Net::Sockets::SocketOptionLevel optionLevel, System::Net::Sockets::SocketOptionName optionName, System::Object ^ optionValue);
public void SetSocketOption (System.Net.Sockets.SocketOptionLevel optionLevel, System.Net.Sockets.SocketOptionName optionName, object optionValue);
member this.SetSocketOption : System.Net.Sockets.SocketOptionLevel * System.Net.Sockets.SocketOptionName * obj -> unit
Public Sub SetSocketOption (optionLevel As SocketOptionLevel, optionName As SocketOptionName, optionValue As Object)

Parámetros

optionLevel
SocketOptionLevel

Uno de los valores de SocketOptionLevel.

optionName
SocketOptionName

Uno de los valores de SocketOptionName.

optionValue
Object

LingerOption o MulticastOption que contiene el valor de la opción.

Excepciones

optionValue es null.

Error al intentar acceder al socket.

El Socket se ha cerrado.

Ejemplos

En el ejemplo de código siguiente se establecen los LingerOption valores de tiempo de espera y Send .

// Specifies that the Socket will linger for 10 seconds after Close is called.
LingerOption^ lingerOption = gcnew LingerOption(true, 10);
s->SetSocketOption(SocketOptionLevel::Socket, SocketOptionName::Linger, lingerOption);
// The socket will linger for 10 seconds after Socket.Close is called.
var lingerOption = new LingerOption(true, 10);
s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, lingerOption);
' 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)

Comentarios

Socket las opciones determinan el comportamiento del objeto actual Socket. Use esta sobrecarga para establecer las Lingeropciones , AddMembershipy DropMembershipSocket . Para la Linger opción , use Socket para el optionLevel parámetro . Para AddMembership y DropMembership, use IP. Si desea obtener el valor actual de cualquiera de las opciones enumeradas anteriormente, use el GetSocketOption 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.

Consulte también

Se aplica a