Пример #1
0
 public NetAcceptor(int port) throws IOException {
   AsynchronousChannelGroup group =
       AsynchronousChannelGroup.withCachedThreadPool(
           Executors.newCachedThreadPool(), 1); // server连接接收线程池
   serverChannel = AsynchronousServerSocketChannel.open(group);
   serverChannel.bind(new InetSocketAddress(port));
 }
Пример #2
0
  public void start() throws IOException, ExecutionException, InterruptedException {
    AsynchronousServerSocketChannel server = AsynchronousServerSocketChannel.open();
    server.bind(new InetSocketAddress(getPort()));

    while (true) {
      new ChannelHandler(server.accept().get()).handle();
    }
  }
Пример #3
0
 public AsyncTimeServerHandler(final int port) {
   this.port = port;
   try {
     serverChannel = AsynchronousServerSocketChannel.open();
     serverChannel.bind(new InetSocketAddress(this.port));
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
 public AsyncTimeServerHandler(int port) {
   this.port = port;
   try {
     asynchronousServerSocketChannel = AsynchronousServerSocketChannel.open();
     asynchronousServerSocketChannel.bind(new InetSocketAddress(port));
     System.out.println("The time server is start in port : " + port);
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
 private AsynchronousServerSocketChannel bind(String host, int port) {
   AsynchronousServerSocketChannel serverSocketChannel = null;
   try {
     serverSocketChannel = AsynchronousServerSocketChannel.open(group);
     serverSocketChannel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
     serverSocketChannel.bind(new InetSocketAddress(host, port), BACKLOG);
   } catch (Exception e) {
     log.error("ServerSocket bind error", e);
   }
   return serverSocketChannel;
 }
  @Override
  protected Void call() throws Exception {

    try (AsynchronousServerSocketChannel server = AsynchronousServerSocketChannel.open()) {
      server.bind(new InetSocketAddress(port));

      while (!isCancelled()) {
        Future<AsynchronousSocketChannel> sock = server.accept();
        hsErrProcPool.submit(new ErrorReportDecoder(crashList, sock.get()));
      }
    }

    return null;
  }
Пример #7
0
  public AIOSocketMgr() throws Exception {
    if (!allowInstance) {
      throw new Exception();
    }
    try {
      AsynchronousChannelGroup resourceGroup =
          AsynchronousChannelGroup.withCachedThreadPool(Executors.newCachedThreadPool(), 8);
      server = AsynchronousServerSocketChannel.open(resourceGroup);
      server.bind(new InetSocketAddress(PORT), 100);

      acceptHandler = new AcceptCompletionHandler();
      readHandler = new ReadCompletionHandler();
      authHandler = new AuthSessionCompletionHandler();

      bindProtocol();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
 @Override
 public AsyncFiberServerSocketChannel bind(SocketAddress local, int backlog) throws IOException {
   ac.bind(local, backlog);
   return this;
 }