X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fserial%2Fserver%2FConnectActionServer.java;h=350d3fe40a1320b68f555458a43c3ceec11e8c25;hb=919bbc354cd2555eb0955be0ef2dcf338047d022;hp=42a562d2069bcf275d15dc7dc9316ea1875dcd83;hpb=340e6065e8027c2b3b88549b5761b0b9f6950a53;p=fanfix.git diff --git a/src/be/nikiroo/utils/serial/server/ConnectActionServer.java b/src/be/nikiroo/utils/serial/server/ConnectActionServer.java deleted file mode 100644 index 42a562d..0000000 --- a/src/be/nikiroo/utils/serial/server/ConnectActionServer.java +++ /dev/null @@ -1,152 +0,0 @@ -package be.nikiroo.utils.serial.server; - -import java.io.IOException; -import java.net.Socket; - -import javax.net.ssl.SSLException; - -/** - * Base class used for the server basic handling. - *

- * It represents a single action: a server is expected to execute one action for - * each client action. - * - * @author niki - */ -abstract class ConnectActionServer { - private boolean closing; - - /** - * The underlying {@link ConnectAction}. - *

- * Cannot be NULL. - */ - protected ConnectAction action; - - /** - * Create a new {@link 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, String key) { - action = new ConnectAction(s, true, key) { - @Override - protected void action() throws Exception { - ConnectActionServer.this.serverHello(); - ConnectActionServer.this.action(); - } - - @Override - protected void onError(Exception e) { - ConnectActionServer.this.onError(e); - } - }; - } - - /** - * Send the HELLO message (check that the client sends a String "HELLO" and - * send it back, to check I/O and encryption modes). - * - * @throws IOException - * in case of I/O error - * @throws SSLException - * in case of encryption error - */ - protected void serverHello() throws IOException, SSLException { - String HELLO = action.recString(); - if (!"HELLO".equals(HELLO)) { - throw new SSLException("Server did not accept the encryption key"); - } - action.sendString(HELLO); - } - - /** - * Actually start the process and call the action (synchronous). - */ - public void connect() { - action.connect(); - } - - /** - * Actually start the process and call the action (asynchronous). - */ - public void connectAsync() { - new Thread(new Runnable() { - @Override - public void run() { - connect(); - } - }).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. - * - * @throws Exception - * in case of I/O error - */ - @SuppressWarnings("unused") - public void action() throws Exception { - } - - /** - * Handler called when an unexpected error occurs in the code. - *

- * Will just ignore the error by default. - * - * @param e - * the exception that occurred - */ - protected void onError(@SuppressWarnings("unused") Exception e) { - } -} \ No newline at end of file