X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fserial%2Fserver%2FServerBridge.java;h=0b734c6bbd6ca105b852406b2a97ec64ee71b589;hb=5584adbbbf5444c0039fed2b35dc7d5bb57b71b1;hp=cb06f56369054deb8ab06b6a1e201c7ac1611e62;hpb=08f80ac5fa60738d3ad74c4b5390a0b79ae313d4;p=nikiroo-utils.git diff --git a/src/be/nikiroo/utils/serial/server/ServerBridge.java b/src/be/nikiroo/utils/serial/server/ServerBridge.java index cb06f56..0b734c6 100644 --- a/src/be/nikiroo/utils/serial/server/ServerBridge.java +++ b/src/be/nikiroo/utils/serial/server/ServerBridge.java @@ -9,6 +9,7 @@ import java.net.UnknownHostException; import be.nikiroo.utils.StringUtils; import be.nikiroo.utils.TraceHandler; +import be.nikiroo.utils.Version; import be.nikiroo.utils.serial.Importer; /** @@ -127,16 +128,17 @@ public class ServerBridge extends Server { // Bad impl, not up to date (should work, but not efficient) return new ConnectActionServerString(s, key) { @Override - public void action() throws Exception { - onClientContact(); + public void action(Version clientVersion) throws Exception { + onClientContact(clientVersion); final ConnectActionServerString bridge = this; try { new ConnectActionClientString(forwardToHost, forwardToPort, forwardToKey) { @Override - public void action() throws Exception { - onServerContact(); + public void action(Version serverVersion) + throws Exception { + onServerContact(serverVersion); for (String fromClient = bridge.rec(); fromClient != null; fromClient = bridge .rec()) { @@ -165,15 +167,15 @@ public class ServerBridge extends Server { /** * This is the method that is called each time a client contact us. */ - protected void onClientContact() { - getTraceHandler().trace(">>> CLIENT "); + protected void onClientContact(Version clientVersion) { + getTraceHandler().trace(">>> CLIENT " + clientVersion); } /** * This is the method that is called each time a client contact us. */ - protected void onServerContact() { - getTraceHandler().trace("<<< SERVER"); + protected void onServerContact(Version serverVersion) { + getTraceHandler().trace("<<< SERVER " + serverVersion); getTraceHandler().trace(""); } @@ -198,6 +200,13 @@ public class ServerBridge extends Server { trace("<<< SERVER", data); } + @Override + protected ConnectActionClient getConnectionToMe() + throws UnknownHostException, IOException { + return new ConnectActionClientString(new Socket((String) null, + getPort()), key); + } + @Override public void run() { getTraceHandler().trace( @@ -217,7 +226,6 @@ public class ServerBridge extends Server { * the data to trace */ private void trace(String prefix, String data) { - // TODO: we convert to string and back int size = data == null ? 0 : data.length(); String ssize = StringUtils.formatNumber(size) + "bytes"; @@ -227,14 +235,14 @@ public class ServerBridge extends Server { try { while (data.startsWith("ZIP:") || data.startsWith("B64:")) { if (data.startsWith("ZIP:")) { - data = StringUtils.unbase64s(data.substring(4), true); + data = StringUtils.unzip64s(data.substring(4)); } else if (data.startsWith("B64:")) { - data = StringUtils.unbase64s(data.substring(4), false); + data = StringUtils.unzip64s(data.substring(4)); } } InputStream stream = new ByteArrayInputStream( - data.getBytes("UTF-8")); + StringUtils.getBytes(data)); try { Object obj = new Importer().read(stream).getValue(); if (obj == null) {