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.
- ServerSocket(int)
- Creates a server socket on a specified port.
- ServerSocket(int, int)
- Creates a server socket, binds it to the specified local port and listens to it.
- accept()
- Accepts a connection.
- close()
- Closes the server socket.
- getInetAddress()
- Gets the address to which the socket is connected.
- getLocalPort()
- Gets the port on which the socket is listening.
- setSocketFactory(SocketImplFactory)
- Sets the system's server SocketImplFactory.
- toString()
- Returns the implementation address and implementation port of this ServerSocket as a String.
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.
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
getInetAddress
public InetAddress getInetAddress()
- Gets the address to which the socket is connected.
getLocalPort
public int getLocalPort()
- Gets the port on which the socket is listening.
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.
close
public void close() throws IOException
- Closes the server socket.
- Throws: IOException
- IO error when closing the socket.
toString
public String toString()
- Returns the implementation address and implementation port of this ServerSocket as a String.
- Overrides:
- toString in class Object
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