java - ServerSocket loses connections without any errors -


i'm trying use socketserver generate web pages, js scripts , other things. looks this:

serversocket serversocket = new serversocket(port); while (!stop) {     socket socket = serversocket.accept();     new thread() { @override ...         inputstream inputstream = socket.getinputstream();         outputstream outputstream = socket.getoutputstream();         // , here reading requests , writing responses     } }.start(); } 

and of times works. chrome receives pages server.

but! today i've noticed, if makes lot of requests enough - server starts refuse connection. chrome gives me this:

net::err_socket_not_connected 

on server side can't see errors in try-catch.

what i'm doing wrong?

this strange, because have issuing waaay toooo maaany requests fail. perhaps not showing of code?

in case, here happening:

the serversocket( int port ) constructor using internally delegates new serversocket( int port, int backlog, inetaddress bindaddr ) constructor, passing value 50 backlog. number of connections can pending while server busy.

the server busy moment .accept() call returns until next invocation of .accept(). if server has lot of work between calls .accept(), (i.e. if call create new thread takes long time,) server unresponsive during time, , if enough connections arrive during time, connections past 50th refused.

so, either supply larger backlog, or, (more likely,) restructure code server not take such long time between calls .accept().


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -