I'm currently developing an asynchronous server and client communication using nio2 asynchronous channels. How can I use it asynchronous. Do I need to open up a Thread for each connection? But this is not asynchronous??
public class JavaAsyncServer {
public static void main(String[] args) throws InterruptedException, ExecutionException {
try {
AsynchronousServerSocketChannel listener = AsynchronousServerSocketChannel.open().bind(new InetSocketAddress(5000));
while(true){
listener.accept().get();
System.out.println("Accept");
}
} catch (IOException ex) {
Logger.getLogger(JavaAsyncServer.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
It works well. If I connect via browser it prints accept. But how can I handle messages now?