From 2764a232788e6d820ebe95419730a319eea1bd3c Mon Sep 17 00:00:00 2001 From: Julian T Date: Tue, 29 Sep 2020 15:10:59 +0200 Subject: Added java and net assignments --- sem5/oop/m7/src/InputHandler.java | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 sem5/oop/m7/src/InputHandler.java (limited to 'sem5/oop/m7/src/InputHandler.java') diff --git a/sem5/oop/m7/src/InputHandler.java b/sem5/oop/m7/src/InputHandler.java new file mode 100644 index 0000000..c6b87d3 --- /dev/null +++ b/sem5/oop/m7/src/InputHandler.java @@ -0,0 +1,30 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; + +public class InputHandler extends Thread { + private Node node; + + public InputHandler(Node node) { + this.node = node; + } + + public void run() { + BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + + try { + String line; + while ((line = in.readLine()) != null) { + char cmd = line.charAt(0); + Message msg = null; + if (cmd == '#' || cmd == '!') { + msg = new PingMessage(this.node.name, line.substring(1), cmd == '!'); + } else { + msg = new TextMessage(this.node.name, "", line); + } + this.node.sendMsgLocal(msg); + } + } catch (Exception e){ + System.err.printf("Send err: %s%n", e); + } + } +} -- cgit v1.2.3