SHARE
TWEET

Untitled

a guest Aug 17th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ServerSocketChannel sChannel = null;
  2.     Selector selector = null;
  3.     try {
  4.         sChannel = ServerSocketChannel.open();
  5.         ServerSocket echoServer = sChannel.socket();
  6.         InetSocketAddress addr = new InetSocketAddress(PORT);
  7.         selector = Selector.open();
  8.  
  9.         echoServer.bind(addr);
  10.         sChannel.configureBlocking(false);
  11.         sChannel.register(selector, SelectionKey.OP_ACCEPT);
  12.         System.out.println("Server running.");
  13.     } catch (IOException e) {//If something goes wrong, the server must be stopped
  14.         e.printStackTrace();
  15.     }
  16.  
  17.     while(true) {
  18.         try {
  19.             selector.select();
  20.         } catch (IOException e) {
  21.             e.printStackTrace();
  22.         }
  23.  
  24.         Set<SelectionKey> readyKeys = selector.selectedKeys();
  25.         Iterator<SelectionKey> iterator = readyKeys.iterator();
  26.      
  27. selector.select()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top