1 package be
.nikiroo
.utils
.serial
.server
;
3 import java
.io
.IOException
;
4 import java
.net
.Socket
;
5 import java
.net
.UnknownHostException
;
8 * Base class used for the client basic handling.
10 * It represents a single action: a client is expected to only execute one
15 abstract class ConnectActionClient
{
17 * The underlying {@link ConnectAction}.
21 protected ConnectAction action
;
24 * Create a new {@link ConnectActionClient}.
31 * an optional key to encrypt all the communications (if NULL,
32 * everything will be sent in clear text)
35 * in case of I/O error
36 * @throws UnknownHostException
37 * if the host is not known
38 * @throws IllegalArgumentException
39 * if the port parameter is outside the specified range of valid
40 * port values, which is between 0 and 65535, inclusive
42 public ConnectActionClient(String host
, int port
, String key
)
44 this(new Socket(host
, port
), key
);
48 * Create a new {@link ConnectActionClient}.
51 * the socket to bind to
53 * an optional key to encrypt all the communications (if NULL,
54 * everything will be sent in clear text)
56 public ConnectActionClient(Socket s
, String key
) {
57 action
= new ConnectAction(s
, false, key
) {
59 protected void action() throws Exception
{
60 ConnectActionClient
.this.action();
64 protected void onError(Exception e
) {
65 ConnectActionClient
.this.onError(e
);
71 * Actually start the process and call the action (synchronous).
73 public void connect() {
78 * Actually start the process and call the action (asynchronous).
80 public void connectAsync() {
81 new Thread(new Runnable() {
90 * Method that will be called when an action is performed on the client.
93 * in case of I/O error
95 @SuppressWarnings("unused")
96 public void action() throws Exception
{
100 * Handler called when an unexpected error occurs in the code.
102 * Will just ignore the error by default.
105 * the exception that occurred
107 protected void onError(@SuppressWarnings("unused") Exception e
) {