Version 4.5.0
[nikiroo-utils.git] / src / be / nikiroo / utils / serial / server / ConnectAction.java
index 8f57c628fb18e861c9805174468f5ccb0ce0fba1..10435e299d70febcdeb83f2f10086c41d85339c3 100644 (file)
@@ -108,6 +108,20 @@ abstract class ConnectAction {
                                out = new OutputStreamWriter(s.getOutputStream(), "UTF-8");
                                try {
                                        if (server) {
+                                               String line = in.readLine();
+                                               if (line != null && line.startsWith("VERSION ")) {
+                                                       // "VERSION client-version" (VERSION 1.0.0)
+                                                       Version clientVersion = new Version(
+                                                                       line.substring("VERSION ".length()));
+                                                       this.clientVersion = clientVersion;
+                                                       Version v = negotiateVersion(clientVersion);
+                                                       if (v == null) {
+                                                               v = new Version();
+                                                       }
+
+                                                       sendString("VERSION " + v.toString());
+                                               }
+
                                                action(clientVersion);
                                        } else {
                                                String v = sendString("VERSION " + version.toString());
@@ -119,9 +133,11 @@ abstract class ConnectAction {
                                        }
                                } finally {
                                        out.close();
+                                       out = null;
                                }
                        } finally {
                                in.close();
+                               in = null;
                        }
                } catch (Exception e) {
                        onError(e);
@@ -159,7 +175,8 @@ abstract class ConnectAction {
        protected Object sendObject(Object data) throws IOException,
                        NoSuchFieldException, NoSuchMethodException, ClassNotFoundException {
                synchronized (lock) {
-                       String rep = sendString(new Exporter().append(data).toString(true));
+                       String rep = sendString(new Exporter().append(data).toString(true,
+                                       true));
                        if (rep != null) {
                                return new Importer().read(rep).getValue();
                        }
@@ -253,22 +270,7 @@ abstract class ConnectAction {
                                        contentToSend = false;
                                }
 
-                               String line = in.readLine();
-                               if (server && line != null && line.startsWith("VERSION ")) {
-                                       // "VERSION client-version" (VERSION 1.0.0)
-                                       Version clientVersion = new Version(
-                                                       line.substring("VERSION ".length()));
-                                       this.clientVersion = clientVersion;
-                                       Version v = negotiateVersion(clientVersion);
-                                       if (v == null) {
-                                               v = new Version();
-                                       }
-                                       sendString("VERSION " + v.toString());
-
-                                       line = in.readLine();
-                               }
-
-                               return line;
+                               return in.readLine();
                        }
 
                        return null;