X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fserial%2Fserver%2FConnectActionServer.java;h=aadc06c67503c6aebfa9aae5dc7785c46fce9841;hb=23cf894daa02843da6e6f1b199eaaea29a739f81;hp=85b46a2fdd89f594528d166f78e26a7177eb8e2c;hpb=79ce1a4973eba079ba819ba841d906de42f38e40;p=nikiroo-utils.git diff --git a/src/be/nikiroo/utils/serial/server/ConnectActionServer.java b/src/be/nikiroo/utils/serial/server/ConnectActionServer.java index 85b46a2..aadc06c 100644 --- a/src/be/nikiroo/utils/serial/server/ConnectActionServer.java +++ b/src/be/nikiroo/utils/serial/server/ConnectActionServer.java @@ -2,8 +2,6 @@ package be.nikiroo.utils.serial.server; import java.net.Socket; -import be.nikiroo.utils.Version; - /** * Base class used for the server basic handling. *

@@ -13,6 +11,8 @@ import be.nikiroo.utils.Version; * @author niki */ abstract class ConnectActionServer { + private boolean closing; + /** * The underlying {@link ConnectAction}. *

@@ -20,41 +20,26 @@ abstract class ConnectActionServer { */ protected ConnectAction action; - /** - * Create a new {@link ConnectActionServer} with the current application - * version (see {@link Version#getCurrentVersion()}) as the server version. - * - * @param s - * the socket to bind to - */ - public ConnectActionServer(Socket s) { - this(s, Version.getCurrentVersion()); - } - /** * Create a new {@link ConnectActionServer}. * * @param s * the socket to bind to - * @param version - * the server version + * @param key + * an optional key to encrypt all the communications (if NULL, + * everything will be sent in clear text) */ - public ConnectActionServer(Socket s, Version version) { - action = new ConnectAction(s, true, version) { + public ConnectActionServer(Socket s, String key) { + action = new ConnectAction(s, true, key) { @Override - protected void action(Version clientVersion) throws Exception { - ConnectActionServer.this.action(clientVersion); + protected void action() throws Exception { + ConnectActionServer.this.action(); } @Override protected void onError(Exception e) { ConnectActionServer.this.onError(e); } - - @Override - protected Version negotiateVersion(Version clientVersion) { - return ConnectActionServer.this.negotiateVersion(clientVersion); - } }; } @@ -78,16 +63,59 @@ abstract class ConnectActionServer { } /** - * Method that will be called when an action is performed on the server. + * Stop the client/server connection on behalf of the server (usually, the + * client connects then is allowed to send as many requests as it wants; in + * some cases, though, the server may wish to forcefully close the + * connection and can do via this value, when it is set to TRUE). + *

+ * Example of usage: the client failed an authentication check, cut the + * connection here and now. * - * @param clientVersion - * the client version + * @return TRUE when it is + */ + public boolean isClosing() { + return closing; + } + + /** + * Can be called to stop the client/server connection on behalf of the + * server (usually, the client connects then is allowed to send as many + * requests as it wants; in some cases, though, the server may wish to + * forcefully close the connection and can do so by calling this method). + *

+ * Example of usage: the client failed an authentication check, cut the + * connection here and now. + */ + public void close() { + closing = true; + } + + /** + * The total amount of bytes received. + * + * @return the amount of bytes received + */ + public long getBytesReceived() { + return action.getBytesReceived(); + } + + /** + * The total amount of bytes sent. + * + * @return the amount of bytes sent + */ + public long getBytesSent() { + return action.getBytesSent(); + } + + /** + * Method that will be called when an action is performed on the server. * * @throws Exception * in case of I/O error */ @SuppressWarnings("unused") - public void action(Version clientVersion) throws Exception { + public void action() throws Exception { } /** @@ -100,19 +128,4 @@ abstract class ConnectActionServer { */ protected void onError(@SuppressWarnings("unused") Exception e) { } - - /** - * Method called when we negotiate the version with the client. - *

- * Will return the actual server version by default. - * - * @param clientVersion - * the client version - * - * @return the version to send to the client - */ - protected Version negotiateVersion( - @SuppressWarnings("unused") Version clientVersion) { - return action.getVersion(); - } } \ No newline at end of file