diff --git a/examples/tcp/Makefile b/examples/tcp/Makefile index f5004cc129b10fb3cb62fc957785d5c12061f57e..da81761ace6272ff2aa381b146b9b81943393ad0 100644 --- a/examples/tcp/Makefile +++ b/examples/tcp/Makefile @@ -1,6 +1,6 @@ LCDIR=../.. -LCCJAR=${LCDIR}/compiler/labComm.jar -LCLJAR=${LCDIR}/lib/java/labcomm.jar +LCCJAR=${LCDIR}/compiler/labComm.jar # the LabComm compiler +LCLJAR=${LCDIR}/lib/java/labcomm.jar # the LabComm library JAVA_PKG=labcommTCPtest .PHONY : clean run runserver runOSserver runclient @@ -26,7 +26,7 @@ ${LCLJAR} : ${JAVA_PKG}/gen/FooSample.java: test.lc ${LCCJAR} ${LCC} --javapackage=${JAVA_PKG}.gen --java=${JAVA_PKG}/gen $< -${JAVA_PKG}/gen/FooSample.class: ${JAVA_PKG}/gen/FooSample.java ${LCLJAR} +${JAVA_PKG}/gen/FooSample.class: ${JAVA_PKG}/gen/FooSample.java test.lc ${LCLJAR} javac -cp ${CLASSPATH} $< ${JAVA_PKG}/Example.class: ${JAVA_PKG}/Example.java ${JAVA_PKG}/gen/FooSample.class ${LCLJAR} diff --git a/examples/tcp/labcommTCPtest/client/TestClient.java b/examples/tcp/labcommTCPtest/client/TestClient.java index ef581dc37a2457716a32b20e7156809da143b9ef..d9040fb3475ebaa36f2f85ac5f261d7d2b07205f 100644 --- a/examples/tcp/labcommTCPtest/client/TestClient.java +++ b/examples/tcp/labcommTCPtest/client/TestClient.java @@ -28,8 +28,15 @@ public class TestClient implements Handler { LabCommEncoderChannel e = new LabCommEncoderChannel(out ); FooSample.register(e); FooSample sample = new FooSample(); + int a[] = new int[3]; + a[0] = 1; + a[1] = 2; + a[2] = 3; + + sample.s = "Some random values"; sample.x = 17; sample.y = 42; + sample.a = a; sample.t = 1717; sample.d = 0.42; printSample("Client sending", sample); @@ -57,8 +64,22 @@ public class TestClient implements Handler { } } + private String formatArray(int a[]) { + StringBuilder sb = new StringBuilder(); + sb.append("["); + for(int i=0; i < a.length; i++) { + sb.append(a[i]); + if(i < a.length-1) { + sb.append(", "); + } + } + sb.append("]"); + + return sb.toString(); + } + private void printSample(String header, FooSample sample2) throws Exception { - System.out.format("[TestClient] %s: (%d, %d, %d, %f)\n", header, sample2.x, sample2.y, sample2.t, sample2.d); + System.out.format("[TestClient] %s: (%s, %d, %d, %s, %d, %f )\n", header, sample2.s, sample2.x, sample2.y, formatArray(sample2.a), sample2.t, sample2.d); } public void handle_FooSample(FooSample sample2) throws Exception { diff --git a/examples/tcp/labcommTCPtest/server/TestServer.java b/examples/tcp/labcommTCPtest/server/TestServer.java index d53c7f9bb3f0692c8613fc3cd24cbf7e1f83fd18..b9b6d0b969a05f266510fca8556ec744290185c7 100644 --- a/examples/tcp/labcommTCPtest/server/TestServer.java +++ b/examples/tcp/labcommTCPtest/server/TestServer.java @@ -49,9 +49,16 @@ public class TestServer implements Handler { public void handle_FooSample(FooSample sample) throws Exception { LabCommEncoderChannel e = new LabCommEncoderChannel(out ); FooSample.register(e); - System.out.println("TestServer.handle_FooSample..."); + System.out.println("TestServer.handle_FooSample: "+sample.s); + int tmp[] = new int[2*sample.a.length]; + for (int i = 0; i < sample.a.length;i++) { + tmp[2*i] = tmp[2*i+1] = sample.a[i]; + } + + sample.s = "double!"; sample.x *= 2; sample.y *= 2; + sample.a = tmp; sample.t *= 2; sample.d *= 2; FooSample.encode(e, sample); diff --git a/examples/tcp/test.lc b/examples/tcp/test.lc index fe104e91c58773da0fedb0ad76c60ea3647625ec..b87779d28f2d2f0f6a53d16b02136c236889c789 100644 --- a/examples/tcp/test.lc +++ b/examples/tcp/test.lc @@ -1,6 +1,8 @@ sample struct { + string s; int x; int y; + int a[_]; long t; double d; } FooSample;