Accepting a Connection on a ServerSocketChannel
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 {
}
}
}
Related examples in the same category