Dela via


DatagramSocketImpl.SetOption Method

Definition

Overloads

SetOption(ISocketOption, Object)

Called to set a socket option.

SetOption(Int32, Object)

Enable/disable the option specified by optID.

SetOption(ISocketOption, Object)

Called to set a socket option.

[Android.Runtime.Register("setOption", "(Ljava/net/SocketOption;Ljava/lang/Object;)V", "GetSetOption_Ljava_net_SocketOption_Ljava_lang_Object_Handler", ApiSince=33)]
[Java.Interop.JavaTypeParameters(new System.String[] { "T" })]
protected virtual void SetOption (Java.Net.ISocketOption? name, Java.Lang.Object? value);
[<Android.Runtime.Register("setOption", "(Ljava/net/SocketOption;Ljava/lang/Object;)V", "GetSetOption_Ljava_net_SocketOption_Ljava_lang_Object_Handler", ApiSince=33)>]
[<Java.Interop.JavaTypeParameters(new System.String[] { "T" })>]
abstract member SetOption : Java.Net.ISocketOption * Java.Lang.Object -> unit
override this.SetOption : Java.Net.ISocketOption * Java.Lang.Object -> unit

Parameters

name
ISocketOption

The socket option

value
Object

The value of the socket option. A value of null may be valid for some options.

Attributes

Remarks

Called to set a socket option.

Added in 9.

Java documentation for java.net.DatagramSocketImpl.setOption(java.net.SocketOption<T>, T).

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

SetOption(Int32, Object)

Enable/disable the option specified by optID.

[Android.Runtime.Register("setOption", "(ILjava/lang/Object;)V", "GetSetOption_ILjava_lang_Object_Handler")]
public abstract void SetOption (int optID, Java.Lang.Object? value);
[<Android.Runtime.Register("setOption", "(ILjava/lang/Object;)V", "GetSetOption_ILjava_lang_Object_Handler")>]
abstract member SetOption : int * Java.Lang.Object -> unit

Parameters

optID
Int32

identifies the option

value
Object

the parameter of the socket option

Implements

Attributes

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