1 package be
.nikiroo
.utils
.serial
.server
;
3 import java
.io
.IOException
;
4 import java
.net
.Socket
;
6 import be
.nikiroo
.utils
.Version
;
9 * Base class used for the client basic handling.
11 * It represents a single action: a client is expected to only execute one
16 abstract class ConnectActionClient
{
18 * The underlying {@link ConnectAction}.
22 protected ConnectAction action
;
25 * Create a new {@link ConnectActionClient} with the current application
26 * version (see {@link Version#getCurrentVersion()}) as the client version.
29 * the socket to bind to
31 public ConnectActionClient(Socket s
) {
32 this(s
, Version
.getCurrentVersion());
36 * Create a new {@link ConnectActionClient} with the current application
37 * version (see {@link Version#getCurrentVersion()}) as the client version.
44 * TRUE for an SSL connection, FALSE for plain text
47 * in case of I/O error when creating the socket
49 public ConnectActionClient(String host
, int port
, boolean ssl
)
51 this(Server
.createSocket(host
, port
, ssl
), Version
.getCurrentVersion());
55 * Create a new {@link ConnectActionClient}.
62 * TRUE for an SSL connection, FALSE for plain text
67 * in case of I/O error when creating the socket
69 public ConnectActionClient(String host
, int port
, boolean ssl
,
70 Version version
) throws IOException
{
71 this(Server
.createSocket(host
, port
, ssl
), version
);
75 * Create a new {@link ConnectActionClient}.
78 * the socket to bind to
82 public ConnectActionClient(Socket s
, Version version
) {
83 action
= new ConnectAction(s
, false, version
) {
85 protected void action(Version serverVersion
) throws Exception
{
86 ConnectActionClient
.this.action(serverVersion
);
90 protected void onError(Exception e
) {
91 ConnectActionClient
.this.onError(e
);
95 protected Version
negotiateVersion(Version clientVersion
) {
96 new Exception("Should never be called on a client")
104 * Actually start the process and call the action (synchronous).
106 public void connect() {
111 * Actually start the process and call the action (asynchronous).
113 public void connectAsync() {
114 new Thread(new Runnable() {
123 * Method that will be called when an action is performed on the client.
125 * @param serverVersion
129 * in case of I/O error
131 @SuppressWarnings("unused")
132 public void action(Version serverVersion
) throws Exception
{
136 * Handler called when an unexpected error occurs in the code.
138 * Will just ignore the error by default.
141 * the exception that occurred
143 protected void onError(@SuppressWarnings("unused") Exception e
) {