X-Git-Url: https://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fserial%2Fserver%2FConnectActionServer.java;h=699f3074b44b228ac797e186c0f18da58208d08c;hb=088c1d7a37212c54251438841995aeb8e5b26fad;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..699f307 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}. *
@@ -26,9 +28,12 @@ abstract class ConnectActionServer { * * @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 +41,14 @@ abstract class ConnectActionServer { * * @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) * @param version * the server version */ - public ConnectActionServer(Socket s, Version version) { - action = new ConnectAction(s, true, version) { + public ConnectActionServer(Socket s, String key, Version version) { + action = new ConnectAction(s, true, key, version) { @Override protected void action(Version clientVersion) throws Exception { ConnectActionServer.this.action(clientVersion); @@ -77,6 +85,52 @@ 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.getBytesSent(); + } + /** * Method that will be called when an action is performed on the server. *