X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fserial%2Fserver%2FConnectAction.java;h=10435e299d70febcdeb83f2f10086c41d85339c3;hb=a359464fcf59af8abc6f69ae0e88e42adc6018df;hp=8f57c628fb18e861c9805174468f5ccb0ce0fba1;hpb=79ce1a4973eba079ba819ba841d906de42f38e40;p=nikiroo-utils.git diff --git a/src/be/nikiroo/utils/serial/server/ConnectAction.java b/src/be/nikiroo/utils/serial/server/ConnectAction.java index 8f57c62..10435e2 100644 --- a/src/be/nikiroo/utils/serial/server/ConnectAction.java +++ b/src/be/nikiroo/utils/serial/server/ConnectAction.java @@ -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;