import java.net.Socket;
import java.net.UnknownHostException;
+import be.nikiroo.utils.Version;
+
/**
* Class used for the client basic handling.
* <p>
super(s, key);
}
+ /**
+ * Create a new {@link ConnectActionClientObject} .
+ *
+ * @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 clientVersion
+ * the version of the client
+ */
+ public ConnectActionClientObject(Socket s, String key, Version clientVersion) {
+ super(s, key, clientVersion);
+ }
+
/**
* Create a new {@link ConnectActionClientObject}.
*
super(host, port, key);
}
+ /**
+ * Create a new {@link ConnectActionClientObject}.
+ *
+ * @param host
+ * the host to bind to
+ * @param port
+ * the port to bind to
+ * @param key
+ * an optional key to encrypt all the communications (if NULL,
+ * everything will be sent in clear text)
+ * @param clientVersion
+ * the version of the client
+ *
+ * @throws IOException
+ * in case of I/O error
+ * @throws UnknownHostException
+ * if the IP address of the host could not be determined
+ * @throws IllegalArgumentException
+ * if the port parameter is outside the specified range of valid
+ * port values, which is between 0 and 65535, inclusive
+ */
+ public ConnectActionClientObject(String host, int port, String key,
+ Version clientVersion) throws IOException {
+ super(host, port, key, clientVersion);
+ }
+
/**
* Serialise and send the given object to the server (and return the
* deserialised answer).
NoSuchMethodException, ClassNotFoundException {
return action.sendObject(data);
}
+
+ // Deprecated //
+
+ /**
+ * @deprecated SSL support has been replaced by key-based encryption.
+ * <p>
+ * Please use the version with key encryption (this deprecated
+ * version uses an empty key when <tt>ssl</tt> is TRUE and no
+ * key (NULL) when <tt>ssl</tt> is FALSE).
+ */
+ @Deprecated
+ public ConnectActionClientObject(String host, int port, boolean ssl)
+ throws IOException {
+ this(host, port, ssl ? "" : null);
+ }
+
+ /**
+ * @deprecated SSL support has been replaced by key-based encryption.
+ * <p>
+ * Please use the version with key encryption (this deprecated
+ * version uses an empty key when <tt>ssl</tt> is TRUE and no
+ * key (NULL) when <tt>ssl</tt> is FALSE).
+ */
+ @Deprecated
+ public ConnectActionClientObject(String host, int port, boolean ssl,
+ Version version) throws IOException {
+ this(host, port, ssl ? "" : null, version);
+ }
+
+ /**
+ * @deprecated SSL support has been replaced by key-based encryption.
+ * <p>
+ * Please use the version with key encryption (this deprecated
+ * version uses an empty key when <tt>ssl</tt> is TRUE and no
+ * key (NULL) when <tt>ssl</tt> is FALSE).
+ */
+ @SuppressWarnings("unused")
+ @Deprecated
+ public ConnectActionClientObject(Socket s, boolean ssl) throws IOException {
+ this(s, ssl ? "" : null);
+ }
+
+ /**
+ * @deprecated SSL support has been replaced by key-based encryption.
+ * <p>
+ * Please use the version with key encryption (this deprecated
+ * version uses an empty key when <tt>ssl</tt> is TRUE and no
+ * key (NULL) when <tt>ssl</tt> is FALSE).
+ */
+ @SuppressWarnings("unused")
+ @Deprecated
+ public ConnectActionClientObject(Socket s, boolean ssl, Version version)
+ throws IOException {
+ this(s, ssl ? "" : null, version);
+ }
}
\ No newline at end of file
import java.net.Socket;
import java.net.UnknownHostException;
+import be.nikiroo.utils.Version;
+
/**
* Class used for the client basic handling.
* <p>
super(s, key);
}
+ /**
+ * Create a new {@link ConnectActionClientString}.
+ *
+ * @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 clientVersion
+ * the version of this client
+ */
+ public ConnectActionClientString(Socket s, String key, Version clientVersion) {
+ super(s, key, clientVersion);
+ }
+
/**
* Create a new {@link ConnectActionClientString}.
*
super(host, port, key);
}
+ /**
+ * Create a new {@link ConnectActionClientString}.
+ *
+ * @param host
+ * the host to bind to
+ * @param port
+ * the port to bind to
+ * @param key
+ * an optional key to encrypt all the communications (if NULL,
+ * everything will be sent in clear text)
+ * @param clientVersion
+ * the version of this client
+ *
+ * @throws IOException
+ * in case of I/O error
+ * @throws UnknownHostException
+ * if the IP address of the host could not be determined
+ * @throws IllegalArgumentException
+ * if the port parameter is outside the specified range of valid
+ * port values, which is between 0 and 65535, inclusive
+ */
+ public ConnectActionClientString(String host, int port, String key,
+ Version clientVersion) throws IOException {
+ super(host, port, key, clientVersion);
+ }
+
/**
* Send the given object to the server (and return the answer).
*
public String send(String data) throws IOException {
return action.sendString(data);
}
+
+ // Deprecated //
+
+ /**
+ * @deprecated SSL support has been replaced by key-based encryption.
+ * <p>
+ * Please use the version with key encryption (this deprecated
+ * version uses an empty key when <tt>ssl</tt> is TRUE and no
+ * key (NULL) when <tt>ssl</tt> is FALSE).
+ */
+ @Deprecated
+ public ConnectActionClientString(String host, int port, boolean ssl)
+ throws IOException {
+ this(host, port, ssl ? "" : null);
+ }
+
+ /**
+ * @deprecated SSL support has been replaced by key-based encryption.
+ * <p>
+ * Please use the version with key encryption (this deprecated
+ * version uses an empty key when <tt>ssl</tt> is TRUE and no
+ * key (NULL) when <tt>ssl</tt> is FALSE).
+ */
+ @Deprecated
+ public ConnectActionClientString(String host, int port, boolean ssl,
+ Version version) throws IOException {
+ this(host, port, ssl ? "" : null, version);
+ }
+
+ /**
+ * @deprecated SSL support has been replaced by key-based encryption.
+ * <p>
+ * Please use the version with key encryption (this deprecated
+ * version uses an empty key when <tt>ssl</tt> is TRUE and no
+ * key (NULL) when <tt>ssl</tt> is FALSE).
+ */
+ @SuppressWarnings("unused")
+ @Deprecated
+ public ConnectActionClientString(Socket s, boolean ssl) throws IOException {
+ this(s, ssl ? "" : null);
+ }
+
+ /**
+ * @deprecated SSL support has been replaced by key-based encryption.
+ * <p>
+ * Please use the version with key encryption (this deprecated
+ * version uses an empty key when <tt>ssl</tt> is TRUE and no
+ * key (NULL) when <tt>ssl</tt> is FALSE).
+ */
+ @SuppressWarnings("unused")
+ @Deprecated
+ public ConnectActionClientString(Socket s, boolean ssl, Version version)
+ throws IOException {
+ this(s, ssl ? "" : null, version);
+ }
}
\ No newline at end of file
for (Object data = rec(); true; data = rec()) {
Object rep = null;
try {
- rep = onRequest(this, data, id);
+ rep = onRequest(this, clientVersion, data, id);
if (isClosing()) {
return;
}
* @throws Exception
* in case of an exception, the error will only be logged
*/
- abstract protected Object onRequest(ConnectActionServerObject action,
- Object data, long id) throws Exception;
+ protected Object onRequest(ConnectActionServerObject action,
+ Version clientVersion, Object data,
+ @SuppressWarnings("unused") long id) throws Exception {
+ // TODO: change to abstract when deprecated method is removed
+ // Default implementation for compat
+ return onRequest(action, clientVersion, data);
+ }
+
+ // Deprecated //
+
+ /**
+ * @deprecated SSL support has been replaced by key-based encryption.
+ * <p>
+ * Please use the version with key encryption (this deprecated
+ * version uses an empty key when <tt>ssl</tt> is TRUE and no
+ * key (NULL) when <tt>ssl</tt> is FALSE).
+ */
+ @Deprecated
+ public ServerObject(int port, boolean ssl) throws IOException {
+ this(port, ssl ? "" : null);
+ }
+
+ /**
+ * @deprecated SSL support has been replaced by key-based encryption.
+ * <p>
+ * Please use the version with key encryption (this deprecated
+ * version uses an empty key when <tt>ssl</tt> is TRUE and no
+ * key (NULL) when <tt>ssl</tt> is FALSE).
+ */
+ @Deprecated
+ public ServerObject(String name, int port, boolean ssl) throws IOException {
+ this(name, port, ssl ? "" : null);
+ }
+
+ /**
+ * Will be called if the correct version is not overrided.
+ *
+ * @deprecated use the version with the id.
+ *
+ * @param action
+ * the client action
+ * @param data
+ * the data sent by the client
+ *
+ * @return the answer to return to the client
+ *
+ * @throws Exception
+ * in case of an exception, the error will only be logged
+ */
+ @Deprecated
+ @SuppressWarnings("unused")
+ protected Object onRequest(ConnectActionServerObject action,
+ Version version, Object data) throws Exception {
+ return null;
+ }
}
for (String data = rec(); data != null; data = rec()) {
String rep = null;
try {
- rep = onRequest(this, data, id);
+ rep = onRequest(this, clientVersion, data, id);
if (isClosing()) {
return;
}
*
* @param action
* the client action
+ * @param clientVersion
+ * the client version
* @param data
* the data sent by the client
* @param id
* @throws Exception
* in case of an exception, the error will only be logged
*/
- abstract protected String onRequest(ConnectActionServerString action,
- String data, long id) throws Exception;
+ protected String onRequest(ConnectActionServerString action,
+ Version clientVersion, String data,
+ @SuppressWarnings("unused") long id) throws Exception {
+ // TODO: change to abstract when deprecated method is removed
+ // Default implementation for compat
+ return onRequest(action, clientVersion, data);
+ }
+
+ // Deprecated //
+
+ /**
+ * @deprecated SSL support has been replaced by key-based encryption.
+ * <p>
+ * Please use the version with key encryption (this deprecated
+ * version uses an empty key when <tt>ssl</tt> is TRUE and no
+ * key (NULL) when <tt>ssl</tt> is FALSE).
+ */
+ @Deprecated
+ public ServerString(int port, boolean ssl) throws IOException {
+ this(port, ssl ? "" : null);
+ }
+
+ /**
+ * @deprecated SSL support has been replaced by key-based encryption.
+ * <p>
+ * Please use the version with key encryption (this deprecated
+ * version uses an empty key when <tt>ssl</tt> is TRUE and no
+ * key (NULL) when <tt>ssl</tt> is FALSE).
+ */
+ @Deprecated
+ public ServerString(String name, int port, boolean ssl) throws IOException {
+ this(name, port, ssl ? "" : null);
+ }
+
+ /**
+ * Will be called if the correct version is not overrided.
+ *
+ * @deprecated use the version with the id.
+ *
+ * @param action
+ * the client action
+ * @param data
+ * the data sent by the client
+ *
+ * @return the answer to return to the client
+ *
+ * @throws Exception
+ * in case of an exception, the error will only be logged
+ */
+ @Deprecated
+ @SuppressWarnings("unused")
+ protected String onRequest(ConnectActionServerString action,
+ Version version, String data) throws Exception {
+ return null;
+ }
}
ServerString server = new ServerString(this.getName(), 0, key) {
@Override
protected String onRequest(
- ConnectActionServerString action, String data,
- long id) throws Exception {
+ ConnectActionServerString action, Version version,
+ String data, long id) throws Exception {
return null;
}
ServerString server = new ServerString(this.getName(), 0, key) {
@Override
protected String onRequest(
- ConnectActionServerString action, String data,
- long id) throws Exception {
+ ConnectActionServerString action, Version version,
+ String data, long id) throws Exception {
sent[0] = data;
return "pong";
}
ServerString server = new ServerString(this.getName(), 0, key) {
@Override
protected String onRequest(
- ConnectActionServerString action, String data,
- long id) throws Exception {
+ ConnectActionServerString action, Version version,
+ String data, long id) throws Exception {
sent[0] = data;
action.send("pong");
sent[1] = action.rec();
ServerString server = new ServerString(this.getName(), 0, key) {
@Override
protected String onRequest(
- ConnectActionServerString action, String data,
- long id) throws Exception {
+ ConnectActionServerString action, Version version,
+ String data, long id) throws Exception {
sent[Integer.parseInt(data)] = data;
return "" + (Integer.parseInt(data) * 2);
}
ServerObject server = new ServerObject(this.getName(), 0, key) {
@Override
protected Object onRequest(
- ConnectActionServerObject action, Object data,
- long id) throws Exception {
+ ConnectActionServerObject action, Version version,
+ Object data, long id) throws Exception {
return null;
}
ServerObject server = new ServerObject(this.getName(), 0, key) {
@Override
protected Object onRequest(
- ConnectActionServerObject action, Object data,
- long id) throws Exception {
+ ConnectActionServerObject action, Version version,
+ Object data, long id) throws Exception {
sent[0] = data;
return "pong";
}
ServerObject server = new ServerObject(this.getName(), 0, key) {
@Override
protected Object onRequest(
- ConnectActionServerObject action, Object data,
- long id) throws Exception {
+ ConnectActionServerObject action, Version version,
+ Object data, long id) throws Exception {
sent[0] = data;
action.send("pong");
sent[1] = action.rec();
ServerObject server = new ServerObject(this.getName(), 0, key) {
@Override
protected Object onRequest(
- ConnectActionServerObject action, Object data,
- long id) throws Exception {
+ ConnectActionServerObject action, Version version,
+ Object data, long id) throws Exception {
sent[0] = data;
return new Object[] { "ACK" };
}
ServerObject server = new ServerObject(this.getName(), 0, key) {
@Override
protected Object onRequest(
- ConnectActionServerObject action, Object data,
- long id) throws Exception {
+ ConnectActionServerObject action, Version version,
+ Object data, long id) throws Exception {
sent[(Integer) data] = data;
return ((Integer) data) * 2;
}