org.pf.net
Class PortListener

java.lang.Object
  extended by org.pf.util.ExceptionIgnorer
      extended by org.pf.net.PortListener

public class PortListener
extends ExceptionIgnorer

Encapsulates the functionality to open a port (i.e. server socket) and start listening on it.

Version:
1.1
Author:
Manfred Duchrow

Constructor Summary
PortListener(int port)
          Initialize the new instance with the given port.
PortListener(int port, ExceptionHandler handler)
          Initialize the new instance with the given port and exception handler.
 
Method Summary
 void close()
          Close the underlying socket.
 int getPort()
          Returns the port number this port listener is listening on.
 boolean isOpen()
          Returns true if the server socket is open and can be used.
 java.net.Socket waitForRequest()
          Listen to the port until a request comes in and return the newly created socket that can be used to handle the request.
 
Methods inherited from class org.pf.util.ExceptionIgnorer
exceptionOccurred, getExceptionHandler, setExceptionHandler
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PortListener

public PortListener(int port)
Initialize the new instance with the given port.


PortListener

public PortListener(int port,
                    ExceptionHandler handler)
Initialize the new instance with the given port and exception handler.

Method Detail

waitForRequest

public java.net.Socket waitForRequest()
Listen to the port until a request comes in and return the newly created socket that can be used to handle the request.

If the socket is not opened yet then null will be returned.


close

public void close()
Close the underlying socket.


isOpen

public boolean isOpen()
Returns true if the server socket is open and can be used.


getPort

public int getPort()
Returns the port number this port listener is listening on. If not opened it returns -1.