package at.acdp.urweb.sclient.data; import at.acdp.urweb.RobotCommand; import at.acdp.urweb.URBot; import at.acdp.urweb.sclient.SecondaryClient; import at.acdp.urweb.sclient.URLog; import okhttp3.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; public class ScReadThread implements Runnable { private static final Logger log = LoggerFactory.getLogger(ScReadThread.class); private final String ip; private final URBot urBot; SecondaryClient rde; public ScReadThread(String ip, URBot urBot) { this.ip = ip; this.urBot=urBot; } public SecondaryClient getRde() { return rde; } @Override public void run() { while (true) { try { read(); } catch (Exception e) { log.warn("read thread terminated", e); URLog.add(new Message("read thread terminated", e)); } } } private void read() throws IOException { rde = new SecondaryClient(ip, 30001, urBot); VersionMessage vm = rde.connect(); while (true) { rde.readPackage(); } } public void writeCmd(RobotCommand r) { writeCmd(r.cmd); } private void writeCmd(String s) { if (!s.endsWith("\n")) s += "\n"; log.debug("writecmd: \"" + s + "\""); rde.writeCmd(s); } }