Package org.activecomponents.udp
Class UdpConnectionHandler
- java.lang.Object
- 
- org.activecomponents.udp.UdpConnectionHandler
 
- 
 public class UdpConnectionHandler extends java.lang.ObjectConnection handler for UDP connections.
- 
- 
Field SummaryFields Modifier and Type Field Description protected booleanactiveFlag if the handler is active.protected java.util.List<IConnectionListener>connectionlistenersListeners for new connections.protected java.util.Map<java.net.SocketAddress,Connection>connectionsCurrent connections with remote hosts.static intDEFAULT_CIPHERCipher class ID for default encryptionprotected java.net.DatagramSocketdgsocketThe socket.protected java.util.List<IIncomingListener>inclistenersListeners for incoming messages and packets.protected IIncomingListenerinternalinclistenerInternal listener for incoming messages and packets.protected KeyExchangeGeneratorkeyexgenProvider for randomly generated key exchanges.protected java.util.List<IKeyVerifier>keyverifiersList of externally-provided key verifiers.static intNULL_CIPHERCipher class ID for no encryptionprotected intsymcipherclassidID of the class used as cipher for symmetric encryption.protected IThreadExecutortexecThe thread executor.
 - 
Constructor SummaryConstructors Modifier Constructor Description UdpConnectionHandler(int port, int symcipherclassid, boolean nonblocking, IIncomingListener[] initiallisteners)Creates the connection handler.protectedUdpConnectionHandler(int port, java.net.DatagramSocket inisocket, int symcipherclassid, boolean nonblocking, IIncomingListener[] initiallisteners)Creates the connection handler.UdpConnectionHandler(java.net.DatagramSocket inisocket, int symcipherclassid, boolean nonblocking, IIncomingListener[] initiallisteners)Creates the connection handler.
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddConnectionListener(IConnectionListener listener)Adds a connection listener.Connectionconnect(java.lang.String host, int port)Attempts to connect to a host.voiddisconnect(Connection conn)Terminates a connection.protected voidfireConnectionEstablished(Connection connection)Notifies connection listeners about a new connection.static intgetCipherIdForClass(java.lang.String symcipherclass)Returns a cipher class ID for a class name.ConnectiongetConnection(java.lang.String host, int port)Gets the connection if available.ConnectiongetConnection(java.net.SocketAddress remoteaddr)Gets the connection if available.intgetPort()Gets the local port.voidholePunch(java.lang.String remotehost, int remoteport)Attempts to punch a hole in the local firewall for the remote host.static voidmain(java.lang.String[] args)Test.voidremoveConnectionListener(IConnectionListener listener)Removes a connection listener.voidstart(IThreadExecutor texec)Starts the handling of incoming packages.voidstop()Stops the handling of incoming packages.
 
- 
- 
- 
Field Detail- 
NULL_CIPHERpublic static final int NULL_CIPHER Cipher class ID for no encryption- See Also:
- Constant Field Values
 
 - 
DEFAULT_CIPHERpublic static final int DEFAULT_CIPHER Cipher class ID for default encryption- See Also:
- Constant Field Values
 
 - 
texecprotected IThreadExecutor texec The thread executor.
 - 
keyexgenprotected KeyExchangeGenerator keyexgen Provider for randomly generated key exchanges.
 - 
keyverifiersprotected java.util.List<IKeyVerifier> keyverifiers List of externally-provided key verifiers.
 - 
dgsocketprotected java.net.DatagramSocket dgsocket The socket.
 - 
connectionsprotected java.util.Map<java.net.SocketAddress,Connection> connections Current connections with remote hosts.
 - 
activeprotected volatile boolean active Flag if the handler is active.
 - 
symcipherclassidprotected int symcipherclassid ID of the class used as cipher for symmetric encryption.
 - 
connectionlistenersprotected java.util.List<IConnectionListener> connectionlisteners Listeners for new connections.
 - 
inclistenersprotected java.util.List<IIncomingListener> inclisteners Listeners for incoming messages and packets.
 - 
internalinclistenerprotected IIncomingListener internalinclistener Internal listener for incoming messages and packets.
 
- 
 - 
Constructor Detail- 
UdpConnectionHandlerpublic UdpConnectionHandler(int port, int symcipherclassid, boolean nonblocking, IIncomingListener[] initiallisteners)Creates the connection handler.- Parameters:
- port- The port.
- inisocket- Pre-initialized socket, overrides port argument, can be null.
- symcipherclass- Class used for symmetric encryption.
- Throws:
- java.net.SocketException- Socket exception.
 
 - 
UdpConnectionHandlerpublic UdpConnectionHandler(java.net.DatagramSocket inisocket, int symcipherclassid, boolean nonblocking, IIncomingListener[] initiallisteners)Creates the connection handler.- Parameters:
- port- The port.
- inisocket- Pre-initialized socket, overrides port argument, can be null.
- symcipherclass- Class used for symmetric encryption.
- Throws:
- java.net.SocketException- Socket exception.
 
 - 
UdpConnectionHandlerprotected UdpConnectionHandler(int port, java.net.DatagramSocket inisocket, int symcipherclassid, boolean nonblocking, IIncomingListener[] initiallisteners)Creates the connection handler.- Parameters:
- port- The port.
- inisocket- Pre-initialized socket, overrides port argument, can be null.
- symcipherclass- Class used for symmetric encryption.
- Throws:
- java.net.SocketException- Socket exception.
 
 
- 
 - 
Method Detail- 
startpublic void start(IThreadExecutor texec) Starts the handling of incoming packages.
 - 
stoppublic void stop() Stops the handling of incoming packages.
 - 
mainpublic static void main(java.lang.String[] args) throws java.lang.ExceptionTest.- Throws:
- java.lang.Exception
 
 - 
connectpublic Connection connect(java.lang.String host, int port) Attempts to connect to a host.- Parameters:
- host- Remote host.
- port- Remote port.
- Returns:
- The connection.
 
 - 
disconnectpublic void disconnect(Connection conn) Terminates a connection.- Parameters:
- conn- The connection.
 
 - 
getPortpublic int getPort() Gets the local port.- Returns:
- The local port.
 
 - 
getConnectionpublic Connection getConnection(java.lang.String host, int port) Gets the connection if available.- Parameters:
- host- The remote host.
- port- The remote port.
- Returns:
- The connection, null if unavailable.
 
 - 
getConnectionpublic Connection getConnection(java.net.SocketAddress remoteaddr) Gets the connection if available.- Parameters:
- remoteaddr- The remote address.
- Returns:
- The connection, null if unavailable.
 
 - 
holePunchpublic void holePunch(java.lang.String remotehost, int remoteport)Attempts to punch a hole in the local firewall for the remote host.- Parameters:
- remotehost- The remote host.
- remoteport- The port the remote host is using.
 
 - 
addConnectionListenerpublic void addConnectionListener(IConnectionListener listener) Adds a connection listener.- Parameters:
- listener- The listener.
 
 - 
removeConnectionListenerpublic void removeConnectionListener(IConnectionListener listener) Removes a connection listener.- Parameters:
- listener- The listener.
 
 - 
getCipherIdForClasspublic static final int getCipherIdForClass(java.lang.String symcipherclass) Returns a cipher class ID for a class name.- Parameters:
- symcipherclass- The class name.
- Returns:
- The ID.
 
 - 
fireConnectionEstablishedprotected void fireConnectionEstablished(Connection connection) Notifies connection listeners about a new connection.- Parameters:
- connection- The connection.
 
 
- 
 
-