/** * close: close the socket and stream * * @return: true for success, false for error */ protected boolean close() { _dlog("Do main thread closing..."); if (_sock != null && !_sock.isClosed()) { _dlog("Closing the receiving thread"); try { _sock.close(); _in.close(); _out.close(); _sock = null; _in = null; _out = null; _dlog("Success!"); } catch (IOException e) { if (!_server.noException()) { _elog(e.toString()); } if (_server.debugMode()) { e.printStackTrace(); } return false; } } _sock = null; _in = null; _out = null; _dlog("Cancel the user input thread"); if (_userNet != null) { _userNet.stop(); _userNet.join(); // guaranteed to be closed _userNet = null; } if (_userSock != null && !_userSock.isClosed()) { _dlog("Closing the user input thread"); // Stop the user thread try { _userSock.close(); _userIn.close(); _userOut.close(); _userSock = null; _userIn = null; _userOut = null; _dlog("Success!"); } catch (IOException e) { if (!_server.noException()) { _elog(e.toString()); } if (_server.debugMode()) { e.printStackTrace(); } return false; } } _userSock = null; _userIn = null; _userOut = null; /* Cancel all client nodes */ _dlog("Finished"); return true; /* CAUTION: _server is never cleared */ }