public void run() {
        try {
            server = ServerSocketChannel.open();
            server.configureBlocking(false);
            server.socket().bind(new java.net.InetSocketAddress(port));

            Selector selector = Selector.open();
            server.register(selector, server.validOps());

            while(true) {
                selector.select();
                Set<SelectionKey> keys = selector.selectedKeys();
                Iterator i = keys.iterator();

                while(i.hasNext()) {
                    SelectionKey key = (SelectionKey) i.next();

                    // Remove the current key
                    i.remove();

                    // if isAccetable == true
                    // then a client required a connection
                    if (key.isAcceptable()) {
                        SocketChannel client = server.accept();
                        client.configureBlocking(false);
                        WebSocket c = new WebSocket(client, this);
                        client.register(selector, SelectionKey.OP_READ, c);
                    }

                    // if isReadable == true
                    // then the server is ready to read
                    if (key.isReadable()) {
                        WebSocket conn = (WebSocket)key.attachment();
                        conn.handleRead();
                    }
                }
            }
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        //System.out.println("End of WebSocketServer socket thread: " + Thread.currentThread());
    }