public RemoteConsoleServer(InputStream remoteClientIn, OutputStream remoteClientOut) {
        this.remoteClientIn  = remoteClientIn;
        this.remoteClientOut = remoteClientOut;

        inputStream = new FilterInputStream(remoteClientIn) {
            private void checkRead() throws IOException {
                if (available() == 0) {
                    if (passwordMode)
                        writer.write(ESCAPE + "P");
                    else
                        writer.write(ESCAPE + "R");
                    writer.flush();
                } 
            }
            
            public int read() throws IOException {
                checkRead();
                int result = super.read();
                if (result == -1)
                    System.exit(0);
                return result;
            }
            
            
            public int read(byte[] data) throws IOException {
                checkRead();
                int result = super.read(data);
                if (result == -1)
                    System.exit(0);
                return result;
            }


            public int read(byte[] data, int offset, int length) throws IOException {
                checkRead();
                int result = super.read(data, offset, length);
                if (result == -1)
                    System.exit(0);
                return result;
            }
        };
        
        outputStream = new PrintStream(remoteClientOut, true);
        
        try {
            reader = new BufferedReader(new InputStreamReader(inputStream, "utf-8")) {
                private void checkRead() throws IOException {
                    if (!ready()) {
                        if (passwordMode)
                            writer.write(ESCAPE + "P");
                        else
                            writer.write(ESCAPE + "R");
                        writer.flush();
                    } 
                }
        
                public int read(char[] cbuf, int off, int len) throws IOException {
                    checkRead();
                    return super.read(cbuf, off, len);
                }
            };
            
            writer = new PrintWriter(new OutputStreamWriter(outputStream, "utf-8"), true);
        }
        catch (UnsupportedEncodingException e) {
            throw new Error(e);
        }
        
        setTextAttributes(Enigma.getSystemTextAttributes("attributes.console.default"));
    }