| 1 | package be.nikiroo.utils.serial.server; |
| 2 | |
| 3 | import java.io.IOException; |
| 4 | import java.net.Socket; |
| 5 | import java.net.UnknownHostException; |
| 6 | |
| 7 | import be.nikiroo.utils.Version; |
| 8 | |
| 9 | /** |
| 10 | * Class used for the client basic handling. |
| 11 | * <p> |
| 12 | * It represents a single action: a client is expected to only execute one |
| 13 | * action. |
| 14 | * |
| 15 | * @author niki |
| 16 | */ |
| 17 | public class ConnectActionClientObject extends ConnectActionClient { |
| 18 | /** |
| 19 | * Create a new {@link ConnectActionClientObject} with the current |
| 20 | * application version (see {@link Version#getCurrentVersion()}) as the |
| 21 | * client version. |
| 22 | * |
| 23 | * @param s |
| 24 | * the socket to bind to |
| 25 | */ |
| 26 | public ConnectActionClientObject(Socket s) { |
| 27 | super(s); |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Create a new {@link ConnectActionClientObject} with the current |
| 32 | * application version (see {@link Version#getCurrentVersion()}) as the |
| 33 | * client version. |
| 34 | * |
| 35 | * @param host |
| 36 | * the host to bind to |
| 37 | * @param port |
| 38 | * the port to bind to |
| 39 | * @param ssl |
| 40 | * TRUE for an SSL connection, FALSE for plain text |
| 41 | * |
| 42 | * @throws IOException |
| 43 | * in case of I/O error |
| 44 | * @throws UnknownHostException |
| 45 | * if the IP address of the host could not be determined |
| 46 | * @throws IllegalArgumentException |
| 47 | * if the port parameter is outside the specified range of valid |
| 48 | * port values, which is between 0 and 65535, inclusive |
| 49 | */ |
| 50 | public ConnectActionClientObject(String host, int port, boolean ssl) |
| 51 | throws IOException { |
| 52 | super(host, port, ssl); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Create a new {@link ConnectActionClientObject}. |
| 57 | * |
| 58 | * @param host |
| 59 | * the host to bind to |
| 60 | * @param port |
| 61 | * the port to bind to |
| 62 | * @param ssl |
| 63 | * TRUE for an SSL connection, FALSE for plain text |
| 64 | * @param version |
| 65 | * the client version |
| 66 | * |
| 67 | * @throws IOException |
| 68 | * in case of I/O error |
| 69 | * @throws UnknownHostException |
| 70 | * if the IP address of the host could not be determined |
| 71 | * @throws IllegalArgumentException |
| 72 | * if the port parameter is outside the specified range of valid |
| 73 | * port values, which is between 0 and 65535, inclusive |
| 74 | */ |
| 75 | public ConnectActionClientObject(String host, int port, boolean ssl, |
| 76 | Version version) throws IOException { |
| 77 | super(host, port, ssl, version); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Create a new {@link ConnectActionClientObject}. |
| 82 | * |
| 83 | * @param s |
| 84 | * the socket to bind to |
| 85 | * @param version |
| 86 | * the client version |
| 87 | */ |
| 88 | public ConnectActionClientObject(Socket s, Version version) { |
| 89 | super(s, version); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Serialise and send the given object to the server (and return the |
| 94 | * deserialised answer). |
| 95 | * |
| 96 | * @param data |
| 97 | * the data to send |
| 98 | * |
| 99 | * @return the answer, which can be NULL |
| 100 | * |
| 101 | * @throws IOException |
| 102 | * in case of I/O error |
| 103 | * @throws NoSuchFieldException |
| 104 | * if the serialised data contains information about a field |
| 105 | * which does actually not exist in the class we know of |
| 106 | * @throws NoSuchMethodException |
| 107 | * if a class described in the serialised data cannot be created |
| 108 | * because it is not compatible with this code |
| 109 | * @throws ClassNotFoundException |
| 110 | * if a class described in the serialised data cannot be found |
| 111 | */ |
| 112 | public Object send(Object data) throws IOException, NoSuchFieldException, |
| 113 | NoSuchMethodException, ClassNotFoundException { |
| 114 | return action.sendObject(data); |
| 115 | } |
| 116 | } |