示例#1
0
  public void run() {
    // Configure the server.
    ServerBootstrap bootstrap =
        new ServerBootstrap(
            new NioServerSocketChannelFactory(
                Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));

    // Set up the event pipeline factory.
    bootstrap.setPipelineFactory(
        new ChannelPipelineFactory() {
          public ChannelPipeline getPipeline() throws Exception {
            return Channels.pipeline(new PortUnificationServerHandler());
          }
        });

    // Bind and start to accept incoming connections.
    bootstrap.bind(new InetSocketAddress(port));
  }
示例#2
0
  public static void main(String[] args) {
    ConsoleHandler ch = new ConsoleHandler();
    ch.setLevel(Level.FINE);
    Logger.getLogger("").addHandler(ch);
    Logger.getLogger("").setLevel(Level.FINE);

    // Configure the server.
    ServerBootstrap bootstrap =
        new ServerBootstrap(
            new NioServerSocketChannelFactory(
                Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));

    // bootstrap.setOption("child.tcpNoDelay", true);

    // Set up the event pipeline factory.
    bootstrap.setPipelineFactory(new WebSocketServerPipelineFactory());

    // Bind and start to accept incoming connections.
    bootstrap.bind(new InetSocketAddress(9000));

    System.out.println("Web Socket Server started on localhost:9000.");
  }