HTTP server in Java with long time reposnse -
i want write http server long time response. prepared loop:
serversocketchannel = serversocketchannel.open(); serversocketchannel.socket().bind(new inetsocketaddress(inetaddress.getbyname("127.0.0.1"), 8000)); while (serversocketchannel.isopen()) { try { system.out.println("waiting..."); socketchannel socketchannel = serversocketchannel.accept(); system.out.println("the new connection open ;)"); } catch (ioexception ex) { system.out.println(ex.getmessage()); logger.getlogger(serverhttp.class.getname()).log(level.severe, null, ex); } }
i want catch new connection user's browser, put list, , thread take , parse it. have problem on beginning: code above freezing in method serversocketchannel.accept().
when add socketchannel.close() working correctly, don't want close connection in place, because need long time response.
look @ javadoc serversocketchannel:
"if channel in non-blocking mode method return null if there no pending connections. otherwise block indefinitely until new connection available or i/o error occurs."
this seems describe "freezing" experiencing.
you can open serversocketchannel in non-blocking mode:
serversocketchannel.configureblocking(false);
Comments
Post a Comment