| 1 | package be.nikiroo.utils.serial.server; |
| 2 | |
| 3 | import java.io.IOException; |
| 4 | import java.net.Socket; |
| 5 | |
| 6 | /** |
| 7 | * Class used for the server basic handling. |
| 8 | * <p> |
| 9 | * It represents a single action: a server is expected to execute one action for |
| 10 | * each client action. |
| 11 | * |
| 12 | * @author niki |
| 13 | */ |
| 14 | public class ConnectActionServerObject extends ConnectActionServer { |
| 15 | /** |
| 16 | * Create a new {@link ConnectActionServerObject} as the server version. |
| 17 | * |
| 18 | * @param s |
| 19 | * the socket to bind to |
| 20 | * @param key |
| 21 | * an optional key to encrypt all the communications (if NULL, |
| 22 | * everything will be sent in clear text) |
| 23 | */ |
| 24 | public ConnectActionServerObject(Socket s, String key) { |
| 25 | super(s, key); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Serialise and send the given object to the client. |
| 30 | * |
| 31 | * @param data |
| 32 | * the data to send |
| 33 | * |
| 34 | * @throws IOException |
| 35 | * in case of I/O error |
| 36 | * @throws NoSuchFieldException |
| 37 | * if the serialised data contains information about a field |
| 38 | * which does actually not exist in the class we know of |
| 39 | * @throws NoSuchMethodException |
| 40 | * if a class described in the serialised data cannot be created |
| 41 | * because it is not compatible with this code |
| 42 | * @throws ClassNotFoundException |
| 43 | * if a class described in the serialised data cannot be found |
| 44 | */ |
| 45 | public void send(Object data) throws IOException, NoSuchFieldException, |
| 46 | NoSuchMethodException, ClassNotFoundException { |
| 47 | action.sendObject(data); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * (Flush the data to the client if needed and) retrieve its answer. |
| 52 | * |
| 53 | * @return the deserialised answer (which can actually be NULL) |
| 54 | * |
| 55 | * @throws IOException |
| 56 | * in case of I/O error |
| 57 | * @throws NoSuchFieldException |
| 58 | * if the serialised data contains information about a field |
| 59 | * which does actually not exist in the class we know of |
| 60 | * @throws NoSuchMethodException |
| 61 | * if a class described in the serialised data cannot be created |
| 62 | * because it is not compatible with this code |
| 63 | * @throws ClassNotFoundException |
| 64 | * if a class described in the serialised data cannot be found |
| 65 | * @throws java.lang.NullPointerException |
| 66 | * if the counter part has no data to send |
| 67 | */ |
| 68 | public Object rec() throws NoSuchFieldException, NoSuchMethodException, |
| 69 | ClassNotFoundException, IOException, java.lang.NullPointerException { |
| 70 | return action.recObject(); |
| 71 | } |
| 72 | } |