public synchronized void restart() throws UnknownHostException, IOException, LoginException, ConnectionException { Log.d("", "Riavvio della connessione"); if (t_ping != null) t_ping.interrupt(); t_ping = null; close(); connect(); restart_connection = false; AccountUser a = Status.getInstance().getUtente(); if (a != null) { Messaggio valida_versione = CommunicationMessageCreator.getInstance().createIsValidVersion(Status.CURRENT_VERSION); write(valida_versione.getComando()); valida_versione.setResponse(read()); if (CommunicationParser.getInstance().parseValidateVersion(valida_versione)) { Messaggio relog = CommunicationMessageCreator.getInstance() .createLoginAuthcode(a.getID(), a.getAuthCode()); write(relog.getComando()); relog.setResponse(read()); if (!CommunicationParser.getInstance().parseLoginAuthcode(relog)) throw new LoginException("Errore durante il relog"); } } }
public void disconnect() { try { send(CommunicationMessageCreator.getInstance().createExitMessage()); in.close(); out.close(); socket.close(); } catch (IOException e) { e.printStackTrace(); } catch (LoginException e) { e.printStackTrace(); } catch (ConnectionException e) { e.printStackTrace(); } }