Condividi tramite


ServerSocket Constructors

Definition

Overloads

ServerSocket()

Creates an unbound server socket.

ServerSocket(Int32)

Creates a server socket, bound to the specified port.

ServerSocket(Int32, Int32)

Creates a server socket and binds it to the specified local port number, with the specified backlog.

ServerSocket(IntPtr, JniHandleOwnership)

A constructor used when creating managed representations of JNI objects; called by the runtime.

ServerSocket(Int32, Int32, InetAddress)

Create a server with the specified port, listen backlog, and local IP address to bind to.

ServerSocket()

Creates an unbound server socket.

[Android.Runtime.Register(".ctor", "()V", "")]
public ServerSocket ();
Attributes

Exceptions

if an error occurs while creating the socket.

Remarks

Creates an unbound server socket.

Java documentation for java.net.ServerSocket.ServerSocket().

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

ServerSocket(Int32)

Creates a server socket, bound to the specified port.

[Android.Runtime.Register(".ctor", "(I)V", "")]
public ServerSocket (int port);
[<Android.Runtime.Register(".ctor", "(I)V", "")>]
new Java.Net.ServerSocket : int -> Java.Net.ServerSocket

Parameters

port
Int32

the port number, or 0 to use a port number that is automatically allocated.

Attributes

Exceptions

if an error occurs while creating the socket.

Remarks

Creates a server socket, bound to the specified port. A port number of 0 means that the port number is automatically allocated, typically from an ephemeral port range. This port number can then be retrieved by calling #getLocalPort getLocalPort.

The maximum queue length for incoming connection indications (a request to connect) is set to 50. If a connection indication arrives when the queue is full, the connection is refused.

If the application has specified a server socket factory, that factory's createSocketImpl method is called to create the actual socket implementation. Otherwise a "plain" socket is created.

If there is a security manager, its checkListen method is called with the port argument as its argument to ensure the operation is allowed. This could result in a SecurityException.

Java documentation for java.net.ServerSocket.ServerSocket(int).

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

ServerSocket(Int32, Int32)

Creates a server socket and binds it to the specified local port number, with the specified backlog.

[Android.Runtime.Register(".ctor", "(II)V", "")]
public ServerSocket (int port, int backlog);
[<Android.Runtime.Register(".ctor", "(II)V", "")>]
new Java.Net.ServerSocket : int * int -> Java.Net.ServerSocket

Parameters

port
Int32

the port number, or 0 to use a port number that is automatically allocated.

backlog
Int32

requested maximum length of the queue of incoming connections.

Attributes

Exceptions

if an error occurs while creating the socket.

Remarks

Creates a server socket and binds it to the specified local port number, with the specified backlog. A port number of 0 means that the port number is automatically allocated, typically from an ephemeral port range. This port number can then be retrieved by calling #getLocalPort getLocalPort.

The maximum queue length for incoming connection indications (a request to connect) is set to the backlog parameter. If a connection indication arrives when the queue is full, the connection is refused.

If the application has specified a server socket factory, that factory's createSocketImpl method is called to create the actual socket implementation. Otherwise a "plain" socket is created.

If there is a security manager, its checkListen method is called with the port argument as its argument to ensure the operation is allowed. This could result in a SecurityException.

The backlog argument is the requested maximum number of pending connections on the socket. Its exact semantics are implementation specific. In particular, an implementation may impose a maximum length or may choose to ignore the parameter altogther. The value provided should be greater than 0. If it is less than or equal to 0, then an implementation specific default will be used.

Java documentation for java.net.ServerSocket.ServerSocket(int, int).

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

ServerSocket(IntPtr, JniHandleOwnership)

A constructor used when creating managed representations of JNI objects; called by the runtime.

protected ServerSocket (IntPtr javaReference, Android.Runtime.JniHandleOwnership transfer);
new Java.Net.ServerSocket : nativeint * Android.Runtime.JniHandleOwnership -> Java.Net.ServerSocket

Parameters

javaReference
IntPtr

nativeint

A IntPtrcontaining a Java Native Interface (JNI) object reference.

transfer
JniHandleOwnership

A JniHandleOwnershipindicating how to handle javaReference

Remarks

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

ServerSocket(Int32, Int32, InetAddress)

Create a server with the specified port, listen backlog, and local IP address to bind to.

[Android.Runtime.Register(".ctor", "(IILjava/net/InetAddress;)V", "")]
public ServerSocket (int port, int backlog, Java.Net.InetAddress? bindAddr);
[<Android.Runtime.Register(".ctor", "(IILjava/net/InetAddress;)V", "")>]
new Java.Net.ServerSocket : int * int * Java.Net.InetAddress -> Java.Net.ServerSocket

Parameters

port
Int32

the port number, or 0 to use a port number that is automatically allocated.

backlog
Int32

requested maximum length of the queue of incoming connections.

bindAddr
InetAddress

the local InetAddress the server will bind to

Attributes

Exceptions

if an error occurs while creating the socket.

Remarks

Create a server with the specified port, listen backlog, and local IP address to bind to. The bindAddr argument can be used on a multi-homed host for a ServerSocket that will only accept connect requests to one of its addresses. If bindAddr is null, it will default accepting connections on any/all local addresses. The port must be between 0 and 65535, inclusive. A port number of 0 means that the port number is automatically allocated, typically from an ephemeral port range. This port number can then be retrieved by calling #getLocalPort getLocalPort.

If there is a security manager, this method calls its checkListen method with the port argument as its argument to ensure the operation is allowed. This could result in a SecurityException.

The backlog argument is the requested maximum number of pending connections on the socket. Its exact semantics are implementation specific. In particular, an implementation may impose a maximum length or may choose to ignore the parameter altogther. The value provided should be greater than 0. If it is less than or equal to 0, then an implementation specific default will be used.

Added in 1.1.

Java documentation for java.net.ServerSocket.ServerSocket(int, int, java.net.InetAddress).

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