ISocketOptions.SetOption(Int32, Object) Method

Definition

Enable/disable the option specified by optID.

[Android.Runtime.Register("setOption", "(ILjava/lang/Object;)V", "GetSetOption_ILjava_lang_Object_Handler:Java.Net.ISocketOptionsInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")]
public void SetOption (int optID, Java.Lang.Object? value);
[<Android.Runtime.Register("setOption", "(ILjava/lang/Object;)V", "GetSetOption_ILjava_lang_Object_Handler:Java.Net.ISocketOptionsInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")>]
abstract member SetOption : int * Java.Lang.Object -> unit

Parameters

optID
Int32

identifies the option

value
Object

the parameter of the socket option

Attributes

Exceptions

if an error occurs setting the option value.

Remarks

Enable/disable the option specified by optID. If the option is to be enabled, and it takes an option-specific "value", this is passed in value. The actual type of value is option-specific, and it is an error to pass something that isn't of the expected type: <BR>

SocketImpl s;
            ...
            s.setOption(SO_LINGER, new Integer(10));
               // OK - set SO_LINGER w/ timeout of 10 sec.
            s.setOption(SO_LINGER, new Double(10));
               // ERROR - expects java.lang.Integer

If the requested option is binary, it can be set using this method by a java.lang.Boolean: <BR>

s.setOption(TCP_NODELAY, Boolean.TRUE);
               // OK - enables TCP_NODELAY, a binary option

<BR> Any option can be disabled using this method with a Boolean.FALSE: <BR>

s.setOption(TCP_NODELAY, Boolean.FALSE);
               // OK - disables TCP_NODELAY
            s.setOption(SO_LINGER, Boolean.FALSE);
               // OK - disables SO_LINGER

<BR> For an option that has a notion of on and off, and requires a non-boolean parameter, setting its value to anything other than Boolean.FALSE implicitly enables it. <BR> Throws SocketException if the option is unrecognized, the socket is closed, or some low-level error occurred <BR>

Java documentation for java.net.SocketOptions.setOption(int, java.lang.Object).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to