public class ServerSocket extends Object
Constructor and Description |
---|
ServerSocket(int locport)
Creates a server socket, bound to the specified port.
|
ServerSocket(int locport,
int nqueue)
Creates a server socket and binds it to the specified local port
number, with the specified backlog.
|
ServerSocket(int locport,
int nqueue,
InetAddress locaddr)
Create a server with the specified port, listen backlog, and
local IP address to bind to.
|
Modifier and Type | Method and Description |
---|---|
Socket |
accept() |
void |
close() |
InetAddress |
getInetAddress() |
int |
getLocalPort() |
int |
getSoTimeout() |
protected void |
implAccept(Socket socket) |
void |
setSecure(boolean negotiate) |
static void |
setSocketFactory(SocketImplFactory socketimplfactory) |
void |
setSoTimeout(int i) |
String |
toString()
Returns a string representation of the object.
|
public ServerSocket(int locport) throws IOException
0
creates a socket on any free port.
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.
locport
- the port number, or 0
to use any
free port.IOException
- if an I/O error occurs when opening the socket.SecurityException
- if a security manager exists and its checkListen
method doesn't allow the operation.public ServerSocket(int locport, int nqueue) throws IOException
0
creates a socket on any
free port.
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 must be a positive
value greater than 0. If the value passed if equal or less
than 0, then the default value will be assumed.
locport
- the specified port, or 0
to use
any free port.nqueue
- ?IOException
- if an I/O error occurs when opening the socket.SecurityException
- if a security manager exists and its checkListen
method doesn't allow the operation.SocketImpl
,
SocketImplFactory.createSocketImpl()
,
setSocketFactory(java.net.SocketImplFactory)
,
SecurityManager.checkListen(int)
public ServerSocket(int locport, int nqueue, InetAddress locaddr) throws IOException
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 must be a positive
value greater than 0. If the value passed if equal or less
than 0, then the default value will be assumed.
locport
- the local TCP portnqueue
- ?locaddr
- ?SecurityException
- if a security manager exists and
its checkListen
method doesn't allow the operation.IOException
- if an I/O error occurs when opening the socket.public Socket accept() throws IOException
IOException
- ?public void close() throws IOException
IOException
- ?public InetAddress getInetAddress()
public int getLocalPort()
public int getSoTimeout() throws IOException
IOException
- ?protected final void implAccept(Socket socket) throws IOException
socket
- ?IOException
- ?public void setSoTimeout(int i) throws SocketException
i
- ?SocketException
- ?public void setSecure(boolean negotiate) throws SocketException
negotiate
- ?SocketException
- ?public static void setSocketFactory(SocketImplFactory socketimplfactory) throws IOException
socketimplfactory
- ?IOException
- ?public String toString()
Object
toString
method returns a string that
"textually represents" this object. The result should
be a concise but informative representation that is easy for a
person to read.
It is recommended that all subclasses override this method.
The toString
method for class Object
returns a string consisting of the name of the class of which the
object is an instance, the at-sign character `@
', and
the unsigned hexadecimal representation of the hash code of the
object.