Accepting a Connection on a ServerSocketChannel : ServerSocketChannel « Network « Java Tutorial






import java.net.InetSocketAddress;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;

public class Main {
  public static void main(String[] argv) throws Exception {
    ServerSocketChannel ssChannel = ServerSocketChannel.open();
    ssChannel.configureBlocking(false);
    int port = 80;
    ssChannel.socket().bind(new InetSocketAddress(port));
    int localPort = ssChannel.socket().getLocalPort();

    SocketChannel sChannel = ssChannel.accept();

    if (sChannel == null) {
    } else {
    }
  }
}








19.15.ServerSocketChannel
19.15.1.ServerSocketChannel
19.15.2.New IO Hello Server
19.15.3.Test non-blocking accept() using ServerSocketChannel
19.15.4.Accepting a Connection on a ServerSocketChannel
19.15.5.Using a Selector to Manage Non-Blocking Server Sockets
19.15.6.Detecting When a Non-Blocking Socket Is Closed by the Remote Host