X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fserial%2Fserver%2FConnectActionServer.java;h=350d3fe40a1320b68f555458a43c3ceec11e8c25;hb=505be508ae7d3fb48122be548b310a238cfb91eb;hp=85b46a2fdd89f594528d166f78e26a7177eb8e2c;hpb=79ce1a4973eba079ba819ba841d906de42f38e40;p=fanfix.git diff --git a/src/be/nikiroo/utils/serial/server/ConnectActionServer.java b/src/be/nikiroo/utils/serial/server/ConnectActionServer.java index 85b46a2..350d3fe 100644 --- a/src/be/nikiroo/utils/serial/server/ConnectActionServer.java +++ b/src/be/nikiroo/utils/serial/server/ConnectActionServer.java @@ -13,6 +13,8 @@ import be.nikiroo.utils.Version; * @author niki */ abstract class ConnectActionServer { + private boolean closing; + /** * The underlying {@link ConnectAction}. *

@@ -21,14 +23,16 @@ abstract class ConnectActionServer { protected ConnectAction action; /** - * Create a new {@link ConnectActionServer} with the current application - * version (see {@link Version#getCurrentVersion()}) as the server version. + * Create a new {@link ConnectActionServer}, using the current version. * * @param s * the socket to bind to + * @param key + * an optional key to encrypt all the communications (if NULL, + * everything will be sent in clear text) */ - public ConnectActionServer(Socket s) { - this(s, Version.getCurrentVersion()); + public ConnectActionServer(Socket s, String key) { + this(s, key, Version.getCurrentVersion()); } /** @@ -36,11 +40,14 @@ abstract class 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) + * @param serverVersion + * the version of this server,that will be sent to the client */ - public ConnectActionServer(Socket s, Version version) { - action = new ConnectAction(s, true, version) { + public ConnectActionServer(Socket s, String key, Version serverVersion) { + action = new ConnectAction(s, true, key, serverVersion) { @Override protected void action(Version clientVersion) throws Exception { ConnectActionServer.this.action(clientVersion); @@ -77,11 +84,57 @@ abstract class ConnectActionServer { }).start(); } + /** + * 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. + * + * @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.getBytesWritten(); + } + /** * Method that will be called when an action is performed on the server. * * @param clientVersion - * the client version + * the version of the client connected to this server * * @throws Exception * in case of I/O error