Commit 6de6a6b8 authored by Sven Gestegård Robertz's avatar Sven Gestegård Robertz
Browse files

added main program for example

parent 3cccb339
......@@ -3,12 +3,26 @@ LCC=java -jar ${LCDIR}/compiler/labComm.jar
CLASSPATH=.:${LCDIR}/lib/java/labcomm.jar
JAVA_PKG=labcommTCPtest
.PHONY : clean run runserver runOSserver runclient
#### The main example #########################
run : ${JAVA_PKG}/Example.class ${JAVA_PKG}/server/TestServer.class ${JAVA_PKG}/client/TestClient.class
java -cp ${CLASSPATH} $(<:.class=)
###############################################
### dependencies and parts ####################
###############################################
${JAVA_PKG}/gen/FooSample.java: test.lc
${LCC} --javapackage=${JAVA_PKG}.gen --java=${JAVA_PKG}/gen $<
${JAVA_PKG}/gen/FooSample.class: ${JAVA_PKG}/gen/FooSample.java
javac -cp ${CLASSPATH} $<
${JAVA_PKG}/Example.class: ${JAVA_PKG}/Example.java ${JAVA_PKG}/gen/FooSample.class
javac -cp ${CLASSPATH} $<
${JAVA_PKG}/server/TestServer.class: ${JAVA_PKG}/server/TestServer.java ${JAVA_PKG}/gen/FooSample.class
javac -cp ${CLASSPATH} $<
......@@ -18,7 +32,6 @@ ${JAVA_PKG}/server/OneShotServer.class: ${JAVA_PKG}/server/OneShotServer.java ${
${JAVA_PKG}/client/TestClient.class: ${JAVA_PKG}/client/TestClient.java ${JAVA_PKG}/gen//FooSample.class
javac -cp ${CLASSPATH} $<
.PHONY : clean runserver runclient
runserver : ${JAVA_PKG}/server/TestServer.class
java -cp ${CLASSPATH} $(<:.class=)
......
package labcommTCPtest;
import labcommTCPtest.server.TestServer;
import labcommTCPtest.client.TestClient;
import java.net.Socket;
import java.net.ServerSocket;
public class Example {
public static void main(String a[]) {
String server = "localhost";
int port = 9999;
ServerThread serverThread = new ServerThread(port);
ClientThread clientThread = new ClientThread(server, port);
serverThread.start();
clientThread.start();
}
private static class ServerThread extends Thread {
private int port;
public ServerThread(int port) {
this.port = port;
}
public void run() {
try {
ServerSocket ss = new ServerSocket(port);
Socket s = ss.accept();
TestServer ts = new TestServer(s);
ts.runOne();
} catch (Exception e) {
e.printStackTrace();
}
}
}
private static class ClientThread extends Thread {
private String server;
private int port;
public ClientThread(String server, int port) {
this.server = server;
this.port = port;
}
public void run() {
try {
Socket s = new Socket(server, port);
TestClient c = new TestClient(s);
c.test();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
......@@ -37,7 +37,7 @@ public class TestClient implements Handler {
LabCommDecoderChannel c = new LabCommDecoderChannel(in);
FooSample.register(c,this);
c.run();
c.runOne();
} catch (Exception e) {
e.printStackTrace();
}
......@@ -58,8 +58,7 @@ public class TestClient implements Handler {
}
private void printSample(String header, FooSample sample2) throws Exception {
System.out.println(header);
System.out.format("TestClient.invoke(%d, %d, %d, %f)\n", sample2.x, sample2.y, sample2.t, sample2.d);
System.out.format("[TestClient] %s: (%d, %d, %d, %f)\n", header, sample2.x, sample2.y, sample2.t, sample2.d);
}
public void handle_FooSample(FooSample sample2) throws Exception {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment