org.openuat.util
Class TCPPortServer
java.lang.Object
org.openuat.authentication.AuthenticationEventSender
org.openuat.util.HostServerBase
org.openuat.util.TCPPortServer
- All Implemented Interfaces:
- java.lang.Runnable, HostAuthenticationServer
public class TCPPortServer
- extends HostServerBase
This class represents a listener on a TCP port which responds to incoming authentication requests by delegating any incoming
connection to the HostProtocolHandler class. More specifically, for each incoming TCP connection, the
HostProtocolHandler.startIncomingAuthenticationThread is invoked with the connected TCP socket.
Listening is done in a background thread using blocking accept() calls. After constructing a HostServerSocket object for
a specific port, startListening() needs to be called to start accepting incoming connection.
- Version:
- 1.2, changes to 1.1: startListening is now called start
changes to 1.0: The TCP server socket is now opened in startListening instead of the constructor.
- Author:
- Rene Mayrhofer
|
Constructor Summary |
TCPPortServer(int port,
int protocolTimeoutMs,
boolean keepConnected,
boolean useJSSE)
Initializes the listener by creating the TCP server socket. |
|
Method Summary |
void |
run()
Does the actual listening for incoming connections by calling the blocking accept() on the listening socket in a loop. |
void |
start()
Need to override the startListening method to open the TCP server socket. |
void |
stop()
Need to override the stopListening method to properly close the TCP server socket. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
TCPPortServer
public TCPPortServer(int port,
int protocolTimeoutMs,
boolean keepConnected,
boolean useJSSE)
- Initializes the listener by creating the TCP server socket.
- Parameters:
port - The TCP port to bind to.useJSSE - If set to true, the JSSE API with the default JCE provider of the JVM will be used
for cryptographic operations. If set to false, an internal copy of the Bouncycastle
Lightweight API classes will be used.protocolTimeoutMs - The maximum duration in milliseconds that this authentication
protocol may take before it will abort with an AuthenticationFailed
exception. Set to -1 to disable the timeout.- See Also:
If set to true, the connection to the client will be kept connected after the
registered HostProtocolHandler has finished. This allows the socket to be
reused for additional communication after the first authentication
protocol has been completed.
start
public void start()
throws java.io.IOException
- Need to override the startListening method to open the TCP server socket.
- Specified by:
start in interface HostAuthenticationServer- Overrides:
start in class HostServerBase
- Throws:
java.io.IOException
stop
public void stop()
throws InternalApplicationException
- Need to override the stopListening method to properly close the TCP server socket.
- Specified by:
stop in interface HostAuthenticationServer- Overrides:
stop in class HostServerBase
- Throws:
InternalApplicationException
run
public void run()
- Does the actual listening for incoming connections by calling the blocking accept() on the listening socket in a loop.
For each incoming connection, a new HostProtocolHandler object is created and its startIncomingAuthenticationThread is
used to start a thread that handles the new connection.
2005-2006, Rene Mayrhofer.