Creating a Non-Blocking Server Socket - Java Network

Java examples for Network:Socket

Description

Creating a Non-Blocking Server Socket

Demo Code

import java.awt.Graphics;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.ServerSocketChannel;

public class Main {
  public void m() {
    // Create a non-blocking server socket and check for connections
    try {//from  w  ww.  j a  v  a  2 s.c o  m
      // Create a non-blocking server socket channel on port 80
      ServerSocketChannel ssChannel = ServerSocketChannel.open();
      ssChannel.configureBlocking(false);
      int port = 80;
      ssChannel.socket().bind(new InetSocketAddress(port));

    } catch (IOException e) {
    }
  }
}

Related Tutorials