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