7
|
1 package test;
|
|
2
|
|
3 import java.io.IOException;
|
|
4 import java.net.InetSocketAddress;
|
|
5 import java.nio.channels.SelectionKey;
|
|
6 import java.nio.channels.Selector;
|
|
7 import java.nio.channels.ServerSocketChannel;
|
|
8
|
|
9 public class TestSelector {
|
|
10 public static void main(String[] args) throws IOException{
|
|
11 Selector selector = Selector.open();
|
|
12 ServerSocketChannel ssc = ServerSocketChannel.open();
|
|
13 ssc.configureBlocking(false);
|
|
14 ssc.socket().bind(new InetSocketAddress(8765));
|
|
15 ssc.register(selector, SelectionKey.OP_ACCEPT);
|
|
16
|
|
17
|
|
18 }
|
|
19 }
|