java.net
Class ServerSocket

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.net.ServerSocket

public class ServerSocket
extends Object sample code for java.lang.Object definition code for java.lang.Object

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.

Since:
JDK1.0
See Also:
SocketImpl sample code for java.net.SocketImpl definition code for java.net.SocketImpl , setSocketFactory(java.net.SocketImplFactory) sample code for java.net.ServerSocket.setSocketFactory(java.net.SocketImplFactory) definition code for java.net.ServerSocket.setSocketFactory(java.net.SocketImplFactory) , ServerSocketChannel sample code for java.nio.channels.ServerSocketChannel definition code for java.nio.channels.ServerSocketChannel

Constructor Summary
ServerSocket sample code for java.net.ServerSocket.ServerSocket() definition code for java.net.ServerSocket.ServerSocket() ()
          Creates an unbound server socket.
ServerSocket sample code for java.net.ServerSocket.ServerSocket(int) definition code for java.net.ServerSocket.ServerSocket(int) (int port)
          Creates a server socket, bound to the specified port.
ServerSocket sample code for java.net.ServerSocket.ServerSocket(int, int) definition code for java.net.ServerSocket.ServerSocket(int, int) (int port, int backlog)
          Creates a server socket and binds it to the specified local port number, with the specified backlog.
ServerSocket sample code for java.net.ServerSocket.ServerSocket(int, int, java.net.InetAddress) definition code for java.net.ServerSocket.ServerSocket(int, int, java.net.InetAddress) (int port, int backlog, InetAddress sample code for java.net.InetAddress definition code for java.net.InetAddress  bindAddr)
          Create a server with the specified port, listen backlog, and local IP address to bind to.
 
Method Summary
 Socket sample code for java.net.Socket definition code for java.net.Socket accept sample code for java.net.ServerSocket.accept() definition code for java.net.ServerSocket.accept() ()
          Listens for a connection to be made to this socket and accepts it.
 void bind sample code for java.net.ServerSocket.bind(java.net.SocketAddress) definition code for java.net.ServerSocket.bind(java.net.SocketAddress) (SocketAddress sample code for java.net.SocketAddress definition code for java.net.SocketAddress  endpoint)
          Binds the ServerSocket to a specific address (IP address and port number).
 void bind sample code for java.net.ServerSocket.bind(java.net.SocketAddress, int) definition code for java.net.ServerSocket.bind(java.net.SocketAddress, int) (SocketAddress sample code for java.net.SocketAddress definition code for java.net.SocketAddress  endpoint, int backlog)
          Binds the ServerSocket to a specific address (IP address and port number).
 void close sample code for java.net.ServerSocket.close() definition code for java.net.ServerSocket.close() ()
          Closes this socket.
 ServerSocketChannel sample code for java.nio.channels.ServerSocketChannel definition code for java.nio.channels.ServerSocketChannel getChannel sample code for java.net.ServerSocket.getChannel() definition code for java.net.ServerSocket.getChannel() ()
          Returns the unique ServerSocketChannel sample code for java.nio.channels.ServerSocketChannel definition code for java.nio.channels.ServerSocketChannel object associated with this socket, if any.
 InetAddress sample code for java.net.InetAddress definition code for java.net.InetAddress getInetAddress sample code for java.net.ServerSocket.getInetAddress() definition code for java.net.ServerSocket.getInetAddress() ()
          Returns the local address of this server socket.
 int getLocalPort sample code for java.net.ServerSocket.getLocalPort() definition code for java.net.ServerSocket.getLocalPort() ()
          Returns the port on which this socket is listening.
 SocketAddress sample code for java.net.SocketAddress definition code for java.net.SocketAddress getLocalSocketAddress sample code for java.net.ServerSocket.getLocalSocketAddress() definition code for java.net.ServerSocket.getLocalSocketAddress() ()
          Returns the address of the endpoint this socket is bound to, or null if it is not bound yet.
 int getReceiveBufferSize sample code for java.net.ServerSocket.getReceiveBufferSize() definition code for java.net.ServerSocket.getReceiveBufferSize() ()
          Gets the value of the SO_RCVBUF option for this ServerSocket, that is the proposed buffer size that will be used for Sockets accepted from this ServerSocket.
 boolean getReuseAddress sample code for java.net.ServerSocket.getReuseAddress() definition code for java.net.ServerSocket.getReuseAddress() ()
          Tests if SO_REUSEADDR is enabled.
 int getSoTimeout sample code for java.net.ServerSocket.getSoTimeout() definition code for java.net.ServerSocket.getSoTimeout() ()
          Retrive setting for SO_TIMEOUT.
protected  void implAccept sample code for java.net.ServerSocket.implAccept(java.net.Socket) definition code for java.net.ServerSocket.implAccept(java.net.Socket) (Socket sample code for java.net.Socket definition code for java.net.Socket  s)
          Subclasses of ServerSocket use this method to override accept() to return their own subclass of socket.
 boolean isBound sample code for java.net.ServerSocket.isBound() definition code for java.net.ServerSocket.isBound() ()
          Returns the binding state of the ServerSocket.
 boolean isClosed sample code for java.net.ServerSocket.isClosed() definition code for java.net.ServerSocket.isClosed() ()
          Returns the closed state of the ServerSocket.
 void setPerformancePreferences sample code for java.net.ServerSocket.setPerformancePreferences(int, int, int) definition code for java.net.ServerSocket.setPerformancePreferences(int, int, int) (int connectionTime, int latency, int bandwidth)
          Sets performance preferences for this ServerSocket.
 void setReceiveBufferSize sample code for java.net.ServerSocket.setReceiveBufferSize(int) definition code for java.net.ServerSocket.setReceiveBufferSize(int) (int size)
          Sets a default proposed value for the SO_RCVBUF option for sockets accepted from this ServerSocket.
 void setReuseAddress sample code for java.net.ServerSocket.setReuseAddress(boolean) definition code for java.net.ServerSocket.setReuseAddress(boolean) (boolean on)
          Enable/disable the SO_REUSEADDR socket option.
static void setSocketFactory sample code for java.net.ServerSocket.setSocketFactory(java.net.SocketImplFactory) definition code for java.net.ServerSocket.setSocketFactory(java.net.SocketImplFactory) (SocketImplFactory sample code for java.net.SocketImplFactory definition code for java.net.SocketImplFactory  fac)
          Sets the server socket implementation factory for the application.
 void setSoTimeout sample code for java.net.ServerSocket.setSoTimeout(int) definition code for java.net.ServerSocket.setSoTimeout(int) (int timeout)
          Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds.
 String sample code for java.lang.String definition code for java.lang.String toString sample code for java.net.ServerSocket.toString() definition code for java.net.ServerSocket.toString() ()
          Returns the implementation address and implementation port of this socket as a String.
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Constructor Detail

ServerSocket sample code for java.net.ServerSocket() definition code for java.net.ServerSocket()

public ServerSocket()
             throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Creates an unbound server socket.

Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - IO error when opening the socket.

ServerSocket sample code for java.net.ServerSocket(int) definition code for java.net.ServerSocket(int)

public ServerSocket(int port)
             throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Creates a server socket, bound to the specified port. A port of 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.

Parameters:
port - the port number, or 0 to use any free port.
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if an I/O error occurs when opening the socket.
SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException - if a security manager exists and its checkListen method doesn't allow the operation.
See Also:
SocketImpl sample code for java.net.SocketImpl definition code for java.net.SocketImpl , SocketImplFactory.createSocketImpl() sample code for java.net.SocketImplFactory.createSocketImpl() definition code for java.net.SocketImplFactory.createSocketImpl() , setSocketFactory(java.net.SocketImplFactory) sample code for java.net.ServerSocket.setSocketFactory(java.net.SocketImplFactory) definition code for java.net.ServerSocket.setSocketFactory(java.net.SocketImplFactory) , SecurityManager.checkListen(int) sample code for java.lang.SecurityManager.checkListen(int) definition code for java.lang.SecurityManager.checkListen(int)

ServerSocket sample code for java.net.ServerSocket(int, int) definition code for java.net.ServerSocket(int, int)

public ServerSocket(int port,
                    int backlog)
             throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Creates a server socket and binds it to the specified local port number, with the specified backlog. A port number of 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.

Parameters:
port - the specified port, or 0 to use any free port.
backlog - the maximum length of the queue.
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if an I/O error occurs when opening the socket.
SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException - if a security manager exists and its checkListen method doesn't allow the operation.
See Also:
SocketImpl sample code for java.net.SocketImpl definition code for java.net.SocketImpl , SocketImplFactory.createSocketImpl() sample code for java.net.SocketImplFactory.createSocketImpl() definition code for java.net.SocketImplFactory.createSocketImpl() , setSocketFactory(java.net.SocketImplFactory) sample code for java.net.ServerSocket.setSocketFactory(java.net.SocketImplFactory) definition code for java.net.ServerSocket.setSocketFactory(java.net.SocketImplFactory) , SecurityManager.checkListen(int) sample code for java.lang.SecurityManager.checkListen(int) definition code for java.lang.SecurityManager.checkListen(int)

ServerSocket sample code for java.net.ServerSocket(int, int, java.net.InetAddress) definition code for java.net.ServerSocket(int, int, java.net.InetAddress)

public ServerSocket(int port,
                    int backlog,
                    InetAddress sample code for java.net.InetAddress definition code for java.net.InetAddress  bindAddr)
             throws IOException sample code for java.io.IOException definition code for java.io.IOException 
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.

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.

Parameters:
port - the local TCP port
backlog - the listen backlog
bindAddr - the local InetAddress the server will bind to
Throws:
SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException - if a security manager exists and its checkListen method doesn't allow the operation.
IOException sample code for java.io.IOException definition code for java.io.IOException - if an I/O error occurs when opening the socket.
Since:
JDK1.1
See Also:
SocketOptions sample code for java.net.SocketOptions definition code for java.net.SocketOptions , SocketImpl sample code for java.net.SocketImpl definition code for java.net.SocketImpl , SecurityManager.checkListen(int) sample code for java.lang.SecurityManager.checkListen(int) definition code for java.lang.SecurityManager.checkListen(int)
Method Detail

bind sample code for java.net.ServerSocket.bind(java.net.SocketAddress) definition code for java.net.ServerSocket.bind(java.net.SocketAddress)

public void bind(SocketAddress sample code for java.net.SocketAddress definition code for java.net.SocketAddress  endpoint)
          throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Binds the ServerSocket to a specific address (IP address and port number).

If the address is null, then the system will pick up an ephemeral port and a valid local address to bind the socket.

Parameters:
endpoint - The IP address & port number to bind to.
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if the bind operation fails, or if the socket is already bound.
SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException - if a SecurityManager is present and its checkListen method doesn't allow the operation.
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - if endpoint is a SocketAddress subclass not supported by this socket
Since:
1.4

bind sample code for java.net.ServerSocket.bind(java.net.SocketAddress, int) definition code for java.net.ServerSocket.bind(java.net.SocketAddress, int)

public void bind(SocketAddress sample code for java.net.SocketAddress definition code for java.net.SocketAddress  endpoint,
                 int backlog)
          throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Binds the ServerSocket to a specific address (IP address and port number).

If the address is null, then the system will pick up an ephemeral port and a valid local address to bind the socket.

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.

Parameters:
endpoint - The IP address & port number to bind to.
backlog - The listen backlog length.
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if the bind operation fails, or if the socket is already bound.
SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException - if a SecurityManager is present and its checkListen method doesn't allow the operation.
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - if endpoint is a SocketAddress subclass not supported by this socket
Since:
1.4

getInetAddress sample code for java.net.ServerSocket.getInetAddress() definition code for java.net.ServerSocket.getInetAddress()

public InetAddress sample code for java.net.InetAddress definition code for java.net.InetAddress  getInetAddress()
Returns the local address of this server socket.

Returns:
the address to which this socket is bound, or null if the socket is unbound.

getLocalPort sample code for java.net.ServerSocket.getLocalPort() definition code for java.net.ServerSocket.getLocalPort()

public int getLocalPort()
Returns the port on which this socket is listening.

Returns:
the port number to which this socket is listening or -1 if the socket is not bound yet.

getLocalSocketAddress sample code for java.net.ServerSocket.getLocalSocketAddress() definition code for java.net.ServerSocket.getLocalSocketAddress()

public SocketAddress sample code for java.net.SocketAddress definition code for java.net.SocketAddress  getLocalSocketAddress()
Returns the address of the endpoint this socket is bound to, or null if it is not bound yet.

Returns:
a SocketAddress representing the local endpoint of this socket, or null if it is not bound yet.
Since:
1.4
See Also:
getInetAddress() sample code for java.net.ServerSocket.getInetAddress() definition code for java.net.ServerSocket.getInetAddress() , getLocalPort() sample code for java.net.ServerSocket.getLocalPort() definition code for java.net.ServerSocket.getLocalPort() , bind(SocketAddress) sample code for java.net.ServerSocket.bind(java.net.SocketAddress) definition code for java.net.ServerSocket.bind(java.net.SocketAddress)

accept sample code for java.net.ServerSocket.accept() definition code for java.net.ServerSocket.accept()

public Socket sample code for java.net.Socket definition code for java.net.Socket  accept()
              throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Listens for a connection to be made to this socket and accepts it. The method blocks until a connection is made.

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.

Returns:
the new Socket
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if an I/O error occurs when waiting for a connection.
SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException - if a security manager exists and its checkListen method doesn't allow the operation.
SocketTimeoutException sample code for java.net.SocketTimeoutException definition code for java.net.SocketTimeoutException - if a timeout was previously set with setSoTimeout and the timeout has been reached.
IllegalBlockingModeException sample code for java.nio.channels.IllegalBlockingModeException definition code for java.nio.channels.IllegalBlockingModeException - if this socket has an associated channel, the channel is in non-blocking mode, and there is no connection ready to be accepted
See Also:
SecurityManager.checkAccept(java.lang.String, int) sample code for java.lang.SecurityManager.checkAccept(java.lang.String, int) definition code for java.lang.SecurityManager.checkAccept(java.lang.String, int)

implAccept sample code for java.net.ServerSocket.implAccept(java.net.Socket) definition code for java.net.ServerSocket.implAccept(java.net.Socket)

protected final void implAccept(Socket sample code for java.net.Socket definition code for java.net.Socket  s)
                         throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Subclasses of ServerSocket use this method to override accept() to return their own subclass of socket. So a FooServerSocket will typically hand this method an empty FooSocket. On return from implAccept the FooSocket will be connected to a client.

Parameters:
s - the Socket
Throws:
IllegalBlockingModeException sample code for java.nio.channels.IllegalBlockingModeException definition code for java.nio.channels.IllegalBlockingModeException - if this socket has an associated channel, and the channel is in non-blocking mode
IOException sample code for java.io.IOException definition code for java.io.IOException - if an I/O error occurs when waiting for a connection.
Since:
JDK1.1

close sample code for java.net.ServerSocket.close() definition code for java.net.ServerSocket.close()

public void close()
           throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Closes this socket. Any thread currently blocked in accept() sample code for java.net.ServerSocket.accept() definition code for java.net.ServerSocket.accept() will throw a SocketException sample code for java.net.SocketException definition code for java.net.SocketException .

If this socket has an associated channel then the channel is closed as well.

Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if an I/O error occurs when closing the socket.

getChannel sample code for java.net.ServerSocket.getChannel() definition code for java.net.ServerSocket.getChannel()

public ServerSocketChannel sample code for java.nio.channels.ServerSocketChannel definition code for java.nio.channels.ServerSocketChannel  getChannel()
Returns the unique ServerSocketChannel sample code for java.nio.channels.ServerSocketChannel definition code for java.nio.channels.ServerSocketChannel object associated with this socket, if any.

A server socket will have a channel if, and only if, the channel itself was created via the ServerSocketChannel.open sample code for java.nio.channels.ServerSocketChannel.open() definition code for java.nio.channels.ServerSocketChannel.open() method.

Returns:
the server-socket channel associated with this socket, or null if this socket was not created for a channel
Since:
1.4

isBound sample code for java.net.ServerSocket.isBound() definition code for java.net.ServerSocket.isBound()

public boolean isBound()
Returns the binding state of the ServerSocket.

Returns:
true if the ServerSocket succesfuly bound to an address
Since:
1.4

isClosed sample code for java.net.ServerSocket.isClosed() definition code for java.net.ServerSocket.isClosed()

public boolean isClosed()
Returns the closed state of the ServerSocket.

Returns:
true if the socket has been closed
Since:
1.4

setSoTimeout sample code for java.net.ServerSocket.setSoTimeout(int) definition code for java.net.ServerSocket.setSoTimeout(int)

public void setSoTimeout(int timeout)
                  throws SocketException sample code for java.net.SocketException definition code for java.net.SocketException 
Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds. With this option set to a non-zero timeout, a call to accept() for this ServerSocket will block for only this amount of time. If the timeout expires, a java.net.SocketTimeoutException is raised, though the ServerSocket is still valid. The option must be enabled prior to entering the blocking operation to have effect. The timeout must be > 0. A timeout of zero is interpreted as an infinite timeout.

Parameters:
timeout - the specified timeout, in milliseconds
Throws:
SocketException sample code for java.net.SocketException definition code for java.net.SocketException - if there is an error in the underlying protocol, such as a TCP error.
Since:
JDK1.1
See Also:
getSoTimeout() sample code for java.net.ServerSocket.getSoTimeout() definition code for java.net.ServerSocket.getSoTimeout()

getSoTimeout sample code for java.net.ServerSocket.getSoTimeout() definition code for java.net.ServerSocket.getSoTimeout()

public int getSoTimeout()
                 throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Retrive setting for SO_TIMEOUT. 0 returns implies that the option is disabled (i.e., timeout of infinity).

Returns:
the SO_TIMEOUT value
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if an I/O error occurs
Since:
JDK1.1
See Also:
setSoTimeout(int) sample code for java.net.ServerSocket.setSoTimeout(int) definition code for java.net.ServerSocket.setSoTimeout(int)

setReuseAddress sample code for java.net.ServerSocket.setReuseAddress(boolean) definition code for java.net.ServerSocket.setReuseAddress(boolean)

public void setReuseAddress(boolean on)
                     throws SocketException sample code for java.net.SocketException definition code for java.net.SocketException 
Enable/disable the SO_REUSEADDR socket option.

When a TCP connection is closed the connection may remain in a timeout state for a period of time after the connection is closed (typically known as the TIME_WAIT state or 2MSL wait state). For applications using a well known socket address or port it may not be possible to bind a socket to the required SocketAddress if there is a connection in the timeout state involving the socket address or port.

Enabling SO_REUSEADDR prior to binding the socket using bind(SocketAddress) sample code for java.net.ServerSocket.bind(java.net.SocketAddress) definition code for java.net.ServerSocket.bind(java.net.SocketAddress) allows the socket to be bound even though a previous connection is in a timeout state.

When a ServerSocket is created the initial setting of SO_REUSEADDR is not defined. Applications can use getReuseAddress() sample code for java.net.ServerSocket.getReuseAddress() definition code for java.net.ServerSocket.getReuseAddress() to determine the initial setting of SO_REUSEADDR.

The behaviour when SO_REUSEADDR is enabled or disabled after a socket is bound (See isBound() sample code for java.net.ServerSocket.isBound() definition code for java.net.ServerSocket.isBound() ) is not defined.

Parameters:
on - whether to enable or disable the socket option
Throws:
SocketException sample code for java.net.SocketException definition code for java.net.SocketException - if an error occurs enabling or disabling the SO_RESUEADDR socket option, or the socket is closed.
Since:
1.4
See Also:
getReuseAddress() sample code for java.net.ServerSocket.getReuseAddress() definition code for java.net.ServerSocket.getReuseAddress() , bind(SocketAddress) sample code for java.net.ServerSocket.bind(java.net.SocketAddress) definition code for java.net.ServerSocket.bind(java.net.SocketAddress) , isBound() sample code for java.net.ServerSocket.isBound() definition code for java.net.ServerSocket.isBound() , isClosed() sample code for java.net.ServerSocket.isClosed() definition code for java.net.ServerSocket.isClosed()

getReuseAddress sample code for java.net.ServerSocket.getReuseAddress() definition code for java.net.ServerSocket.getReuseAddress()

public boolean getReuseAddress()
                        throws SocketException sample code for java.net.SocketException definition code for java.net.SocketException 
Tests if SO_REUSEADDR is enabled.

Returns:
a boolean indicating whether or not SO_REUSEADDR is enabled.
Throws:
SocketException sample code for java.net.SocketException definition code for java.net.SocketException - if there is an error in the underlying protocol, such as a TCP error.
Since:
1.4
See Also:
setReuseAddress(boolean) sample code for java.net.ServerSocket.setReuseAddress(boolean) definition code for java.net.ServerSocket.setReuseAddress(boolean)

toString sample code for java.net.ServerSocket.toString() definition code for java.net.ServerSocket.toString()

public String sample code for java.lang.String definition code for java.lang.String  toString()
Returns the implementation address and implementation port of this socket as a String.

Overrides:
toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() in class Object sample code for java.lang.Object definition code for java.lang.Object
Returns:
a string representation of this socket.

setSocketFactory sample code for java.net.ServerSocket.setSocketFactory(java.net.SocketImplFactory) definition code for java.net.ServerSocket.setSocketFactory(java.net.SocketImplFactory)

public static void setSocketFactory(SocketImplFactory sample code for java.net.SocketImplFactory definition code for java.net.SocketImplFactory  fac)
                             throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Sets the server socket implementation factory for the application. The factory can be specified only once.

When an application creates a new server socket, the socket implementation factory's createSocketImpl method is called to create the actual socket implementation.

Passing null to the method is a no-op unless the factory was already set.

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.

Parameters:
fac - the desired factory.
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if an I/O error occurs when setting the socket factory.
SocketException sample code for java.net.SocketException definition code for java.net.SocketException - if the factory has already been defined.
SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException - if a security manager exists and its checkSetFactory method doesn't allow the operation.
See Also:
SocketImplFactory.createSocketImpl() sample code for java.net.SocketImplFactory.createSocketImpl() definition code for java.net.SocketImplFactory.createSocketImpl() , SecurityManager.checkSetFactory() sample code for java.lang.SecurityManager.checkSetFactory() definition code for java.lang.SecurityManager.checkSetFactory()

setReceiveBufferSize sample code for java.net.ServerSocket.setReceiveBufferSize(int) definition code for java.net.ServerSocket.setReceiveBufferSize(int)

public void setReceiveBufferSize(int size)
                          throws SocketException sample code for java.net.SocketException definition code for java.net.SocketException 
Sets a default proposed value for the SO_RCVBUF option for sockets accepted from this ServerSocket. The value actually set in the accepted socket must be determined by calling Socket.getReceiveBufferSize() sample code for java.net.Socket.getReceiveBufferSize() definition code for java.net.Socket.getReceiveBufferSize() after the socket is returned by accept() sample code for java.net.ServerSocket.accept() definition code for java.net.ServerSocket.accept() .

The value of SO_RCVBUF is used both to set the size of the internal socket receive buffer, and to set the size of the TCP receive window that is advertized to the remote peer.

It is possible to change the value subsequently, by calling Socket.setReceiveBufferSize(int) sample code for java.net.Socket.setReceiveBufferSize(int) definition code for java.net.Socket.setReceiveBufferSize(int) . However, if the application wishes to allow a receive window larger than 64K bytes, as defined by RFC1323 then the proposed value must be set in the ServerSocket before it is bound to a local address. This implies, that the ServerSocket must be created with the no-argument constructor, then setReceiveBufferSize() must be called and la