Accepting a Connection on a ServerSocketChannel : NIO Socket « Network Protocol « Java






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

1.Non block server
2.Finger Server
3.Reading from a SocketChannel
4.Writing to a SocketChannel
5.Creating a Non-Blocking Server Socket
6.Creating a Non-Blocking Socket: requires a socket channel.
7.Using a Selector to Manage Non-Blocking Server Sockets