devxlogo

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());}

devx-admin

Share the Post: