public void run(){

		try {

			while (started) {

				this.selector.select();

				// wakeup to work on selected keys
				Iterator<SelectionKey> keys = this.selector.selectedKeys().iterator();
				while (keys.hasNext()) {
					SelectionKey key = (SelectionKey) keys.next();

					// this is necessary to prevent the same key from coming up
					// again the next time around.
					keys.remove();

					if (!key.isValid()) {
						continue;
					}

					if (key.isAcceptable()) {
						this.accept(key);
					}
					else if (key.isReadable()) {
						this.readTCP(key);
					}
					else if (key.isWritable()) {
						this.writeTCP(key);
					}

				}

			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}