public FlashTerminalServer(String host, String port, Socket flashSocket) {

        // we now create a new terminal that is used for the system
        // if you want to configure it please refer to the api docs
        emulation = new vt320() {
            /** before sending data transform it using telnet (which is sending it) */
            public void write(byte[] b) {
                try {
                    if (localecho) {
                        emulation.putString(new String(b) + "\r");
                    }
                    telnet.transpose(b);
                } catch (IOException e) {
                    System.err.println("FlashTerminalServer: error sending data: " + e);
                }
            }
        };

        // then we create the actual telnet protocol handler that will negotiate
        // incoming data and transpose outgoing (see above)
        telnet = new TelnetProtocolHandler() {
            /** get the current terminal type */
            public String getTerminalType() {
                return emulation.getTerminalID();
            }

            /** get the current window size */
            public Dimension getWindowSize() {
                return new Dimension(emulation.getColumns(), emulation.getRows());
            }

            /** notify about local echo */
            public void setLocalEcho(boolean echo) {
                localecho = true;
            }

            /** notify about EOR end of record */
            public void notifyEndOfRecord() {
                // only used when EOR needed, like for line mode
                if (debug > 0) {
                    System.err.println("FlashTerminalServer: EOR");
                }
                terminal.redraw();
            }

            /** write data to our back end */
            public void write(byte[] b) throws IOException {
                if (debug > 0) {
                    System.err.println("FlashTerminalServer: writing " + Integer.toHexString(b[0]) + " " + new String
                            (b));
                }
                os.write(b);
            }
        };

        try {
            terminal = new FlashTerminal() {
                public void disconnect() {
                    running = false;
                    try {
                        socket.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            };
            terminal.setVDUBuffer(emulation);

            // open new socket and get streams
            socket = new Socket(host, Integer.parseInt(port));
            is = socket.getInputStream();
            os = socket.getOutputStream();

            (new Thread(this)).start();
            terminal.start(flashSocket);
        } catch (IOException e) {
            System.err.println("FlashTerminalServer: error connecting to remote host: " + e);
        } catch (NumberFormatException e) {
            System.err.println("FlashTerminalServer: " + port + " is not a correct number");
        }
    }