public void run() {
		running = tryToConnect(new InetSocketAddress(uri.getHost(), getPort()));

		while (this.running) {
			SelectionKey key = null;
			try {
				selector.select();
				Set<SelectionKey> keys = selector.selectedKeys();
				Iterator<SelectionKey> i = keys.iterator();

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

					if (key.isConnectable()) {
						finishConnect();
					}

					if (key.isReadable()) {
						conn.handleRead();
					}
				}
			} catch (Exception ex) {
				if (key != null)
					key.cancel();
				onError(ex);
			}
		}

		// System.err.println("WebSocketClient thread ended!");
	}