Commit | Line | Data |
---|---|---|
79ce1a49 NR |
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 | |
8468bb79 NR |
24 | * @param key |
25 | * an optional key to encrypt all the communications (if NULL, | |
26 | * everything will be sent in clear text) | |
79ce1a49 | 27 | */ |
8468bb79 NR |
28 | public ConnectActionServerObject(Socket s, String key) { |
29 | super(s, key); | |
79ce1a49 NR |
30 | } |
31 | ||
32 | /** | |
33 | * Create a new {@link ConnectActionServerObject}. | |
34 | * | |
35 | * @param s | |
36 | * the socket to bind to | |
8468bb79 NR |
37 | * @param key |
38 | * an optional key to encrypt all the communications (if NULL, | |
39 | * everything will be sent in clear text) | |
79ce1a49 NR |
40 | * @param version |
41 | * the server version | |
42 | */ | |
8468bb79 NR |
43 | public ConnectActionServerObject(Socket s, String key, Version version) { |
44 | super(s, key, version); | |
79ce1a49 NR |
45 | } |
46 | ||
47 | /** | |
48 | * Serialise and send the given object to the client. | |
49 | * | |
50 | * @param data | |
51 | * the data to send | |
52 | * | |
53 | * @throws IOException | |
54 | * in case of I/O error | |
55 | * @throws NoSuchFieldException | |
56 | * if the serialised data contains information about a field | |
57 | * which does actually not exist in the class we know of | |
58 | * @throws NoSuchMethodException | |
59 | * if a class described in the serialised data cannot be created | |
60 | * because it is not compatible with this code | |
61 | * @throws ClassNotFoundException | |
62 | * if a class described in the serialised data cannot be found | |
63 | */ | |
64 | public void send(Object data) throws IOException, NoSuchFieldException, | |
65 | NoSuchMethodException, ClassNotFoundException { | |
66 | action.sendObject(data); | |
67 | } | |
68 | ||
69 | /** | |
70 | * (Flush the data to the client if needed and) retrieve its answer. | |
71 | * | |
72 | * @return the deserialised answer (which can actually be NULL) | |
73 | * | |
74 | * @throws IOException | |
75 | * in case of I/O error | |
76 | * @throws NoSuchFieldException | |
77 | * if the serialised data contains information about a field | |
78 | * which does actually not exist in the class we know of | |
79 | * @throws NoSuchMethodException | |
80 | * if a class described in the serialised data cannot be created | |
81 | * because it is not compatible with this code | |
82 | * @throws ClassNotFoundException | |
83 | * if a class described in the serialised data cannot be found | |
84 | * @throws java.lang.NullPointerException | |
85 | * if the counter part has no data to send | |
86 | */ | |
87 | public Object rec() throws NoSuchFieldException, NoSuchMethodException, | |
88 | ClassNotFoundException, IOException, java.lang.NullPointerException { | |
89 | return action.recObject(); | |
90 | } | |
91 | } |