public static void main(String[] args) {

		Thread server = new Thread(new Runnable(){

			@Override
			public void run() {
				
				try {
					ServerSocketChannel serverChannel = ServerSocketChannel.open();
					ServerSocket serverSocket = serverChannel.socket();
					Selector selector = Selector.open();

					serverSocket.bind(new InetSocketAddress(8189));
					serverChannel.configureBlocking(false);
					serverChannel.register(selector, SelectionKey.OP_ACCEPT);
					
					while (true) {
						int select = selector.select();
						if (select == 0) {
							continue ;
						}
						
						Iterator<SelectionKey> it = selector.selectedKeys().iterator();
						while (it.hasNext()) {
							SelectionKey key = it.next();
							// Is a new connection coming in? 
							if (key.isAcceptable()) { 
								System.out.println("======set up=====");
								ServerSocketChannel server = (ServerSocketChannel) key.channel(); 
								SocketChannel channel = server.accept(); 
								registerChannel(selector, channel, SelectionKey.OP_READ);
								//sayHello(channel);
							}
							
							if (key.isReadable()) { 
								readDataFromSocket(key);
							}
							
							if (key.isWritable()) {
//								sayHello((SocketChannel) key.channel());
							}
							it.remove();
						}
					}
					
				} catch (IOException e) {
					e.printStackTrace();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			
		});
		
		server.start();
	}