Socket.SetSocketOption Método
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Establece una Socket opción.
Sobrecargas
| Nombre | Description |
|---|---|
| SetSocketOption(SocketOptionLevel, SocketOptionName, Boolean) |
Establece la opción especificada Socket en el valor especificado Boolean . |
| SetSocketOption(SocketOptionLevel, SocketOptionName, Byte[]) |
Establece la opción especificada Socket en el valor especificado, representado como una matriz de bytes. |
| SetSocketOption(SocketOptionLevel, SocketOptionName, Int32) |
Establece la opción especificada Socket en el valor entero especificado. |
| SetSocketOption(SocketOptionLevel, SocketOptionName, Object) |
Establece la opción especificada Socket en el valor especificado, representado como un objeto . |
SetSocketOption(SocketOptionLevel, SocketOptionName, Boolean)
- Source:
- Socket.cs
- Source:
- Socket.cs
- Source:
- Socket.cs
- Source:
- Socket.cs
- Source:
- Socket.cs
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 SocketOptionLevel valores.
- optionName
- SocketOptionName
Uno de los SocketOptionName valores.
Excepciones
El Socket objeto se ha cerrado.
Error al intentar acceder al socket.
Ejemplos
En el ejemplo de código siguiente se abre un socket y se habilitan las DontLinger opciones de socket y OutOfBandInline .
// 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 mediante 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
- Source:
- Socket.cs
- Source:
- Socket.cs
Establece la opción especificada Socket 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 SocketOptionLevel valores.
- optionName
- SocketOptionName
Uno de los SocketOptionName valores.
Excepciones
Error al intentar acceder al socket.
Se Socket ha cerrado.
Ejemplos
En el ejemplo de código siguiente se establecen los LingerOption valores de tiempo de espera y Send .
// 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 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
SetSocketOption(SocketOptionLevel, SocketOptionName, Int32)
- Source:
- Socket.cs
- Source:
- Socket.cs
- Source:
- Socket.cs
- Source:
- Socket.cs
- Source:
- Socket.cs
Establece la opción especificada Socket en el valor entero especificado.
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 SocketOptionLevel valores.
- optionName
- SocketOptionName
Uno de los SocketOptionName valores.
- optionValue
- Int32
Valor de la opción.
Excepciones
Error al intentar acceder al socket.
Se Socket ha cerrado.
Ejemplos
En el ejemplo de código siguiente se establecen los LingerOption valores de tiempo de espera y Send .
// 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 mediante 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 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
SetSocketOption(SocketOptionLevel, SocketOptionName, Object)
- Source:
- Socket.cs
- Source:
- Socket.cs
- Source:
- Socket.cs
- Source:
- Socket.cs
- Source:
- Socket.cs
Establece la opción especificada Socket 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 SocketOptionLevel valores.
- optionName
- SocketOptionName
Uno de los SocketOptionName valores.
- optionValue
- Object
Objeto LingerOption o MulticastOption que contiene el valor de la opción.
Excepciones
optionValue es null.
Error al intentar acceder al socket.
Se Socket ha cerrado.
Ejemplos
En el ejemplo de código siguiente se establecen los LingerOption valores de tiempo de espera y Send .
// 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.