X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fserial%2Fserver%2FServerBridge.java;h=0b734c6bbd6ca105b852406b2a97ec64ee71b589;hb=abfeadcc2c0da88e32dd49291e8163880fe270f1;hp=2c5d8bf1250fc559f507995d73d9711b56fd8640;hpb=a6a73de36765b85947ac885529da82d3e7189269;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 2c5d8bf..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"; @@ -234,7 +242,7 @@ public class ServerBridge extends Server { } InputStream stream = new ByteArrayInputStream( - data.getBytes("UTF-8")); + StringUtils.getBytes(data)); try { Object obj = new Importer().read(stream).getValue(); if (obj == null) {