Class java.net.ServerSocket
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class java.net.ServerSocket

java.lang.Object
   |
   +----java.net.ServerSocket

public final class ServerSocket
extends Object
The server Socket class. It uses a SocketImpl to implement the actual socket operations. It is done this way so that you are able to change socket implementations depending on the kind of firewall being used. You can change socket implementations by setting the SocketImplFactory.

Constructor Index

 o ServerSocket(int)
Creates a server socket on a specified port.
 o ServerSocket(int, int)
Creates a server socket, binds it to the specified local port and listens to it.

Method Index

 o accept()
Accepts a connection.
 o close()
Closes the server socket.
 o getInetAddress()
Gets the address to which the socket is connected.
 o getLocalPort()
Gets the port on which the socket is listening.
 o setSocketFactory(SocketImplFactory)
Sets the system's server SocketImplFactory.
 o toString()
Returns the implementation address and implementation port of this ServerSocket as a String.

Constructors

 o ServerSocket
  public ServerSocket(int port) throws IOException
Creates a server socket on a specified port.
Parameters:
port - the port
Throws: IOException
IO error when opening the socket.
 o ServerSocket
  public ServerSocket(int port,
                      int backlog) throws IOException
Creates a server socket, binds it to the specified local port and listens to it. You can connect to an annonymous port by specifying the port number to be 0. backlog<\i> specifies how many connection requests the system will queue up while waiting for the ServerSocket to execute accept().
Parameters:
port - the specified port
backlog - the number of queued connect requests pending accept

Methods

 o getInetAddress
  public InetAddress getInetAddress()
Gets the address to which the socket is connected.
 o getLocalPort
  public int getLocalPort()
Gets the port on which the socket is listening.
 o accept
  public Socket accept() throws IOException
Accepts a connection. This method will block until the connection is made.
Throws: IOException
IO error when waiting for the connection.
 o close
  public void close() throws IOException
Closes the server socket.
Throws: IOException
IO error when closing the socket.
 o toString
  public String toString()
Returns the implementation address and implementation port of this ServerSocket as a String.
Overrides:
toString in class Object
 o setSocketFactory
  public static synchronized void setSocketFactory(SocketImplFactory fac) throws IOException
Sets the system's server SocketImplFactory. The factory can be specified only once.
Parameters:
fac - the desired factory
Throws: SocketException
If the factory has already been defined.
Throws: IOException
IO error when setting the socket factor.

All Packages  Class Hierarchy  This Package  Previous  Next  Index