Associate a ServerSocket with a ServerSocketChannel in an NIO App

Associate a ServerSocket with a ServerSocketChannel in an NIO App

This tip shows you how to create a ServerSocketChannel, to which you’ll then associate a standard ServerSocket:

//create the ServerSocketChanneltry{   serverNIO=ServerSocketChannel.open();   serverNIO.configureBlocking(false);   }catch(IOException e)     {System.out.println("
Error: " + e.getMessage());}//indicate the host and the porttry{   InetAddress addr=InetAddress.getByName("localhost");   ISA=new InetSocketAddress(addr,port);              }catch(UnknownHostException e)      {System.out.println("
Error: " + e.getMessage());}//connect a ServerSocket to a ServerSocketChanneltry{   ServerSocket SS=serverNIO.socket();   SS.bind(ISA);   System.out.println("- Ready -");   }catch(IOException e)      {System.out.println("
Error: " + e.getMessage());}
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist