INNER CODE UNIT · Java

createSocketListener

termux/termux-api · app/src/main/java/com/termux/api/SocketListener.java:37

    public static void createSocketListener(Application app) {
        if (listener == null) {
            listener = new Thread(() -> {
                try (LocalServerSocket listen = new LocalServerSocket(LISTEN_ADDRESS)) {
                    while (true) {
                        try (LocalSocket con = listen.accept();
                             DataInputStream in = new DataInputStream(con.getInputStream());
                             BufferedWriter out = new BufferedWriter(new OutputStreamWriter(con.getOutputStream()))) {
                            // only accept connections from Termux programs
                            if (con.getPeerCredentials().getUid() != app.getApplicationInfo().uid) {
                                continue;
                            }
                            try {
                                //System.out.println("connection");
                                int length = in.readUnsignedShort();
                                byte[] b = new byte[length];
                                in.readFully(b);
                                String cmdline = new String(b, StandardCharsets.UTF_8);

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…