|
Java Platform 1.2 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.net.ServerSocket
This class implements server sockets. A server socket waits for requests to come in over the network. It performs some operation based on that request, and then possibly returns a result to the requester.
The actual work of the server socket is performed by an instance
of the SocketImpl
class. An application can
change the socket factory that creates the socket
implementation to configure itself to create sockets
appropriate to the local firewall.
SocketImpl
,
setSocketFactory(java.net.SocketImplFactory)
Constructor Summary | |
ServerSocket(int port)
Creates a server socket on a specified port. |
|
ServerSocket(int port,
int backlog)
Creates a server socket and binds it to the specified local port number. |
|
ServerSocket(int port,
int backlog,
InetAddress bindAddr)
Create a server with the specified port, listen backlog, and local IP address to bind to. |
Method Summary | |
Socket |
accept()
Listens for a connection to be made to this socket and accepts it. |
void |
close()
Closes this socket. |
InetAddress |
getInetAddress()
Returns the local address of this server socket. |
int |
getLocalPort()
Returns the port on which this socket is listening. |
int |
getSoTimeout()
Retrive setting for SO_TIMEOUT. |
protected void |
implAccept(Socket s)
Subclasses of ServerSocket use this method to override accept() to return their own subclass of socket. |
static void |
setSocketFactory(SocketImplFactory fac)
Sets the server socket implementation factory for the application. |
void |
setSoTimeout(int timeout)
Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds. |
String |
toString()
Returns the implementation address and implementation port of this socket as a String . |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
Constructor Detail |
public ServerSocket(int port) 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.
port
- the port number, or 0
to use any
free port.checkListen
method doesn't allow the operation.SocketImpl
,
SocketImplFactory.createSocketImpl()
,
setSocketFactory(java.net.SocketImplFactory)
,
SecurityManager.checkListen(int)
public ServerSocket(int port, int backlog) 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.
port
- the specified port, or 0
to use
any free port.backlog
- the maximum length of the queue.checkListen
method doesn't allow the operation.SocketImpl
,
SocketImplFactory.createSocketImpl()
,
setSocketFactory(java.net.SocketImplFactory)
,
SecurityManager.checkListen(int)
public ServerSocket(int port, int backlog, InetAddress bindAddr) 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.
port
- the local TCP portbacklog
- the listen backlogbindAddr
- the local InetAddress the server will bind tocheckListen
method doesn't allow the operation.SocketConstants
,
SocketOption
,
SocketImpl
,
SecurityManager.checkListen(int)
Method Detail |
public InetAddress getInetAddress()
null
if the socket is not yet connected.public int getLocalPort()
public Socket accept() throws IOException
A new Socket s
is created and, if there is a security manager,
the security manager's checkAccept
method is called
with s.getInetAddress().getHostAddress()
and
s.getPort()
as its arguments to ensure the operation is allowed.
This could result in a SecurityException.
checkListen
method doesn't allow the operation.SecurityManager.checkAccept(java.lang.String, int)
protected final void implAccept(Socket s) throws IOException
public void close() throws IOException
public void setSoTimeout(int timeout) throws SocketException
public int getSoTimeout() throws IOException
public String toString()
String
.public static void setSocketFactory(SocketImplFactory fac) throws IOException
When an application creates a new server socket, the socket
implementation factory's createSocketImpl
method is
called to create the actual socket implementation.
If there is a security manager, this method first calls
the security manager's checkSetFactory
method
to ensure the operation is allowed.
This could result in a SecurityException.
fac
- the desired factory.checkSetFactory
method doesn't allow the operation.SocketImplFactory.createSocketImpl()
,
SecurityManager.checkSetFactory()
|
Java Platform 1.2 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |