public class SocketConnector extends TimeableConnection
Makes a connection to a remote client using TCP protocol. The connector is synchronous and asynchronous; Asynchronous connections have methods that begin with an "a" (ie. aconnect). This class is simply a helper class so you don't have to deal with the connection details. Most of the details should still be implemented by the writer in the SocketHandler instances.
There are four ways to call connect. Aside from the synchronous and asynchronous, the choice is yours to use an internal socket handler or pass in your own external socket handler. The connector is basically amphibious, acting both as an instance-based single-threaded object (ie. one connector per connection) and a non-instance-based multi-threaded object (ie. one connector for multiple handlers/connections). The recommended usage is: if you require listening to connection events for each connection made, then instantiate a connector for each handler (a 1-to-1 connector-handler pairing); if you don't care about connection events (or if your handler fires its own events that you need), then you can instantiate one connector for multiple handlers (ie. a 1-to-many connector-handler pairing).
This class also fully support SSL connections. Certain properties can be set to change the location on where to look for the keystore, passphrase, etc.
The SSL-related key property names are: com.echomine.net.keyStorePath, com.echomine.netkeyStorePassphrase, com.echomine.net.trustManager. By default, the keystore is ~/.keystore, the passphrase is empty, and trust manager uses com.echomine.util.SimpleTrustManager.
listenerList| Constructor and Description |
|---|
SocketConnector()
Do-nothing constructor.
|
SocketConnector(SocketHandler socketHandler) |
| Modifier and Type | Method and Description |
|---|---|
void |
aconnect(ConnectionModel connectionModel)
makes a connection asynchronously using internal socket handler.
|
void |
aconnect(SocketHandler socketHandler,
ConnectionModel connectionModel)
makes a connection asynchronously.
|
void |
connect(ConnectionModel connectionModel)
Synchronous connect method using internal socket handler.
|
void |
connect(SocketHandler socketHandler,
ConnectionModel connectionModel)
Synchronous connect method.
|
SocketHandler |
getSocketHandler() |
void |
setSocketHandler(SocketHandler socketHandler) |
fireConnectionClosed, fireConnectionEstablishedaddConnectionListener, fireConnectionStarting, fireConnectionStartingWithoutVeto, removeConnectionListenerpublic SocketConnector(SocketHandler socketHandler)
public SocketConnector()
public void connect(ConnectionModel connectionModel) throws ConnectionFailedException
ConnectionFailedExceptionpublic void connect(SocketHandler socketHandler, ConnectionModel connectionModel) throws ConnectionFailedException
ConnectionFailedExceptionpublic void aconnect(ConnectionModel connectionModel)
public void aconnect(SocketHandler socketHandler, ConnectionModel connectionModel)
public SocketHandler getSocketHandler()
public void setSocketHandler(SocketHandler socketHandler)
Copyright © 2001-2005 Echomine. All Rights Reserved.