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

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 that is used. You can change socket implementations by setting the SocketImplFactory.
Version:
1.14, 10/24/95
Author:
Jonathan Payne, Arthur van Hoff

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 to which the socket is listening on
 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

 o ServerSocket

  public ServerSocket(int port,
                      int count) 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.
Parameters:
port - the specified port
count - the amt of time to listen for a connection

Methods

 o getInetAddress
  public InetAddress getInetAddress()
Gets the address to which the socket is connected.

 o getLocalPort

  public int getLocalPort()
Gets the port to which the socket is listening on

 o accept

  public Socket accept() throws IOException
Accepts a connection. This method will block until the connection is made.

 o close

  public void close() throws IOException
Closes the server 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.


All Packages    This Package    Previous    Next