Libraryless. Click here for Pure Java version (3596L/24K).
static DialogIO talkTo(int port) { return talkTo("localhost", port); } static int talkTo_defaultTimeout = 10000; // This is the CONNECT timeout static int talkTo_timeoutForReads = 0; // Timeout waiting for answers (0 = no timeout) static ThreadLocal<Map<S, DialogIO>> talkTo_byThread = new ThreadLocal; static DialogIO talkTo(S ip, int port) ctex { S full = ip + ":" + port; Map<S, DialogIO> map = talkTo_byThread.get(); if (map != null && map.containsKey(full)) ret map.get(full); if (isLocalhost(ip) && port == vmPort()) ret talkToThisVM(); ret new talkTo_IO(ip, port); } sclass talkTo_IO extends DialogIO { S ip; int port; Socket s; Writer w; BufferedReader in; *(S *ip, int *port) ctex { s = new Socket; try { if (talkTo_timeoutForReads != 0) s.setSoTimeout(talkTo_timeoutForReads); s.connect(new InetSocketAddress(ip, port), talkTo_defaultTimeout); } catch (Throwable e) { fail("Tried talking to " + ip + ":" + port, e); } w = new OutputStreamWriter(s.getOutputStream(), "UTF-8"); in = new BufferedReader(new InputStreamReader(s.getInputStream(), "UTF-8")); } boolean isLocalConnection() { return s.getInetAddress().isLoopbackAddress(); } boolean isStillConnected() { return !(eos || s.isClosed()); } void sendLine(String line) ctex { lock lock; w.write(line + "\n"); w.flush(); } S readLineImpl() ctex { ret in.readLine(); } public void close() { try { if (!noClose) s.close(); } catch (IOException e) { // whatever } } Socket getSocket() { return s; } }
Began life as a copy of #1000937
download show line numbers debug dex old transpilations
Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, sawdedvomwva, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment