コード例 #1
0
ファイル: Communication.java プロジェクト: rfrancese/016
 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");
     }
   }
 }
コード例 #2
0
ファイル: Communication.java プロジェクト: rfrancese/016
  public synchronized void send(Messaggio m)
      throws IOException, LoginException, ConnectionException {
    if (restart_connection) restart();
    else if (socket == null || socket.isClosed()) {
      connect();
    }

    for (int i = 0; i < 5; i++) {
      try {
        write(m.getComando());
        m.setResponse(read());
        return;
      } catch (IOException e) {
        try {
          restart();
        } catch (IOException e1) {
          e.printStackTrace();
          restart_connection = true;
        }
      }
    }
    throw new ConnectionException();
  }