public static void main(String[] args) throws IOException { final File socketFile = new File(new File(System.getProperty("java.io.tmpdir")), "junixsocket-test.sock"); AFUNIXServerSocket server = AFUNIXServerSocket.newInstance(); server.bind(new AFUNIXSocketAddress(socketFile)); System.out.println("server: " + server); while (!Thread.interrupted()) { System.out.println("Waiting for connection..."); Socket sock = server.accept(); System.out.println("Connected: " + sock); InputStream is = sock.getInputStream(); OutputStream os = sock.getOutputStream(); System.out.println("Saying hello to client " + os); os.write("Hello, dear Client".getBytes()); os.flush(); byte[] buf = new byte[128]; int read = is.read(buf); System.out.println("Client's response: " + new String(buf, 0, read)); os.close(); is.close(); sock.close(); } }
public void fiveSecondTimeoutAndInterruptible(int timeoutMs) { Thread.interrupted(); try { Thread.sleep(timeoutMs); } catch (InterruptedException e) { interrupted.set(true); } }