I have a problem with the server of
Reign of Rebels , that after a few days running, it simply stops accepting connections in an unusual way.
The client tries to connect, it gets no error at first. Instead, it takes 50 - 80 seconds or so for the client to get a connection error. As if the client were negotiating connection.
If server is down, the client gets the message immediatelly.
I believe there's something wrong my code, I'll post the code I use to accept/close connection and would appreciate if somebody sees something weird.
Accepting new connections. I start 10 Threads of these:
1 2 3 4 5 6 7 8
| public void run() { while (true) { MMTCPConnection c = new MMTCPConnection(welcomeSocket, this); addConnection(c); } } |
this is in the constructor of MMTCPConnection :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| Socket connectionSocket; .... try { connectionSocket = ss.accept(); inFromClient = new DataInputStream(connectionSocket.getInputStream()); outToClient = new DataOutputStream( new BufferedOutputStream( connectionSocket.getOutputStream())); }catch (Exception e) { e.printStackTrace(); try { connectionSocket.close(); } catch (IOException e1) { e1.printStackTrace(); } } |
In the class MMTCPConnection, when any error occur (including client closed connection), I call this method :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| Socket connectionSocket; DataOutputStream outToClient; DataInputStream inFromClient;
private void closeConnection() { server.connectionsV.remove(this.id); try { inFromClient.close(); } catch (Exception e) { e.printStackTrace(); }
try { outToClient.close(); } catch (Exception e) { e.printStackTrace(); }
inFromClient=null; outToClient=null;
try { connectionSocket.close(); } catch (IOException e) { e.printStackTrace(); }
System.out.println("closed connection . "+(int)id);
} |
Am I missing something ?