-
-// void pipe() throws IOException {
-// // Set up Server Socket and bind to the port 8000
-// ServerSocketChannel server = ServerSocketChannel.open();
-// SocketAddress endpoint = new InetSocketAddress(8000);
-// server.socket().bind(endpoint);
-//
-// server.configureBlocking(false);
-//
-// // Set up selector so we can run with a single thread but multiplex between 2
-// // channels
-// Selector selector = Selector.open();
-// server.register(selector, SelectionKey.OP_ACCEPT);
-//
-// ByteBuffer buffer = ByteBuffer.allocate(1024);
-//
-// while (true) {
-// // block until data comes in
-// selector.select();
-//
-// Set<SelectionKey> keys = selector.selectedKeys();
-//
-// for (SelectionKey key : keys) {
-// if (!key.isValid()) {
-// // not valid or writable so skip
-// continue;
-// }
-//
-// if (key.isAcceptable()) {
-// // Accept socket channel for client connection
-// ServerSocketChannel channel = (ServerSocketChannel) key.channel();
-// SocketChannel accept = channel.accept();
-// setupConnection(selector, accept);
-// } else if (key.isReadable()) {
-// try {
-// // Read into the buffer from the socket and then write the buffer into the
-// // attached socket.
-// SocketChannel recv = (SocketChannel) key.channel();
-// SocketChannel send = (SocketChannel) key.attachment();
-// recv.read(buffer);
-// buffer.flip();
-// send.write(buffer);
-// buffer.rewind();
-// } catch (IOException e) {
-// e.printStackTrace();
-//
-// // Close sockets
-// if (key.channel() != null)
-// key.channel().close();
-// if (key.attachment() != null)
-// ((SocketChannel) key.attachment()).close();
-// }
-// } else if (key.isWritable()) {
-//
-// }
-// }
-//
-// // Clear keys for next select
-// keys.clear();
-// }
-//
-// }
-
-// public static void mainX(String[] args) throws IOException, InterruptedException {
-// toRawTerminal();
-// try {
-// boolean client = true;
-// if (client) {
-// ReadableByteChannel inChannel;
-// WritableByteChannel outChannel;
-// inChannel = Channels.newChannel(System.in);
-// outChannel = Channels.newChannel(System.out);
-//
-// SocketChannel channel = SocketChannel.open(StandardProtocolFamily.UNIX);
-// channel.connect(ioSocketAddress());
-//
-// new Thread(() -> {
-//
-// try {
-// ByteBuffer buffer = ByteBuffer.allocate(1024);
-// while (true) {
-// if (channel.read(buffer) < 0)
-// break;
-// buffer.flip();
-// outChannel.write(buffer);
-// buffer.rewind();
-// }
-// System.exit(0);
-// } catch (IOException e) {
-// e.printStackTrace();
-// }
-// }, "Read out").start();
-//
-// ByteBuffer buffer = ByteBuffer.allocate(1);
-// while (channel.isConnected()) {
-// if (inChannel.read(buffer) < 0)
-// break;
-// buffer.flip();
-// channel.write(buffer);
-// buffer.rewind();
-// }
-//
-// } else {
-// ServerSocketChannel serverChannel = ServerSocketChannel.open(StandardProtocolFamily.UNIX);
-// serverChannel.bind(ioSocketAddress());
-//
-// SocketChannel channel = serverChannel.accept();
-//
-// while (true) {
-// readSocketMessage(channel).ifPresent(message -> System.out.printf("[Client message] %s", message));
-// Thread.sleep(100);
-// }
-// }
-// } finally {
-// toOriginalTerminal();
-// }
-// }
-//
-// private static Optional<String> readSocketMessage(SocketChannel channel) throws IOException {
-// ByteBuffer buffer = ByteBuffer.allocate(1024);
-// int bytesRead = channel.read(buffer);
-// if (bytesRead < 0)
-// return Optional.empty();
-//
-// byte[] bytes = new byte[bytesRead];
-// buffer.flip();
-// buffer.get(bytes);
-// String message = new String(bytes);
-// return Optional.of(message);
-// }
-//
-// public static void setupConnection(Selector selector, SocketChannel client) throws IOException {
-// // Connect to the remote server
-// SocketAddress address = new InetSocketAddress("192.168.1.74", 8000);
-// SocketChannel remote = SocketChannel.open(address);
-//
-// // Make sockets non-blocking (should be better performance)
-// client.configureBlocking(false);
-// remote.configureBlocking(false);
-//
-// client.register(selector, SelectionKey.OP_READ, remote);
-// remote.register(selector, SelectionKey.OP_READ, client);
-// }
-//
-// static UnixDomainSocketAddress ioSocketAddress() throws IOException {
-// String system = "default";
-// String bundleSn = "org.argeo.slc.jshell";
-//
-// String xdgRunDir = System.getenv("XDG_RUNTIME_DIR");
-// Path baseRunDir = Paths.get(xdgRunDir);
-// Path jshellSocketBase = baseRunDir.resolve("jshell").resolve(system).resolve(bundleSn);
-//
-// Files.createDirectories(jshellSocketBase);
-//
-// Path ioSocketPath = jshellSocketBase.resolve("io");
-//
-// UnixDomainSocketAddress ioSocketAddress = UnixDomainSocketAddress.of(ioSocketPath);
-// System.out.println(ioSocketAddress);
-// return ioSocketAddress;
-// }
-