title: Java Telegram API RpcCall Timeout
body: <p>I have a Problem regarding the Telegram API<br>
  Whenever I do a RpcCall, it always give me a TimeoutException except when I do a NonAuth Call.</p>
  
  <p>I can SignIn with a Number already and I set Authenticated to true in my AbsApiState and still can only do NonAuth Calls</p>
  
  <p>Here is my Code:</p>
  
  <pre><code>private void startApi() throws Exception
  {
      api = new TelegramApi(new MyApiStorage(Moin.config.getProp("useTest").equalsIgnoreCase("true") ? true : false),
              new AppInfo(Moin.api_id, "console", "???", "???", "en"),
              new ApiCallback()
      {
  
          @Override
          public void onAuthCancelled(TelegramApi arg0) 
          {
              System.out.println("AuthCancelled");
          }
  
          @Override
          public void onUpdate(TLAbsUpdates update) 
          {
              System.out.println("Updated | " + update.getClass());
          }
  
          @Override
          public void onUpdatesInvalidated(TelegramApi arg0) 
          {
              System.out.println("Updatefailed");
          }
  
      });
  
      TLConfig config = null;
      config = api.doRpcCallNonAuth(new TLRequestHelpGetConfig());
  
      if(config != null)
          api.getState().updateSettings(config);
      else
          throw new Exception("config is null, could not update DC List");
      login();
  }
  
  
  private void login() throws IOException
  {
          BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
          TLSentCode code = null;
          String defaultNumber = Moin.config.getProp("phoneNumber");
          System.out.println("Enter a Phone Number (Default ist " + defaultNumber + "):");
          String number = reader.readLine();
          if(number.equals(" "))
              number = defaultNumber;
  
          System.out.println("Sending to " + number + " ...");
          try 
          {
              code = api.doRpcCallNonAuth(new TLRequestAuthSendCode(number, 0, Moin.api_id, Moin.api_hash, "en"));
          }
          catch (RpcException e) 
          {
              if (e.getErrorCode() == 303) 
              {
                  int destDC = 0;
                  if (e.getErrorTag().startsWith("NETWORK_MIGRATE_")) 
                  {
                      destDC = Integer.parseInt(e.getErrorTag().substring("NETWORK_MIGRATE_".length()));
                  } 
                  else if (e.getErrorTag().startsWith("PHONE_MIGRATE_")) 
                  {
                      destDC = Integer.parseInt(e.getErrorTag().substring("PHONE_MIGRATE_".length()));
                  }
                  else if (e.getErrorTag().startsWith("USER_MIGRATE_")) 
                  {
                      destDC = Integer.parseInt(e.getErrorTag().substring("USER_MIGRATE_".length()));
                  }
                  else 
                  {
                      e.printStackTrace();
                  }
                  api.switchToDc(destDC);
                  code = api.doRpcCallNonAuth(new TLRequestAuthSendCode(number, 0, Moin.api_id, Moin.api_hash, "en"));
              } 
              else
                  e.printStackTrace();
          }
  
          String hash = code.getPhoneCodeHash();
  
          System.out.println("Please Enter the Code:");
          String smsCode = reader.readLine();
  
          TLAuthorization auth = api.doRpcCallNonAuth(new TLRequestAuthSignIn(number, hash, smsCode));
          api.getState().setAuthenticated(api.getState().getPrimaryDc(), true);
  
  
          //This is where I get the Error
          TLExportedAuthorization test = api.doRpcCall(new TLRequestAuthExportAuthorization(api.getState().getPrimaryDc()));
          System.out.println(test.getId());
  
  
          FileOutputStream stream = new FileOutputStream(Paths.get("").toAbsolutePath().toString() + File.separator + "test.txt");
          try 
          {
              stream.write(test.getBytes().getData());
          } 
          finally 
          {
              stream.close();
          }
  
          TLState state = api.doRpcCall(new TLRequestUpdatesGetState());
          System.out.println(state.getDate() + "  |  " + state.getPts() + "  |  " + state.getQts() + "  |  " + state.getUnreadCount());
  
  
  
  
          TLAbsUser user = auth.getUser();
  
  }
  </code></pre>
  
  <p>And here the Error:</p>
  
  <pre><code>TelegramApi#1001:Timeout Iteration
  TelegramApi#1001:RPC #3: Timeout (14999 ms)
  TelegramApi#1001:Timeout Iteration
  org.telegram.api.engine.TimeoutException
          at org.telegram.api.engine.TelegramApi.doRpcCall(TelegramApi.java:364)
          at org.telegram.api.engine.TelegramApi.doRpcCall(TelegramApi.java:309)
          at org.telegram.api.engine.TelegramApi.doRpcCall(TelegramApi.java:400)
          at org.telegram.api.engine.TelegramApi.doRpcCall(TelegramApi.java:396)
          at at.nonon.telegram.telegram.Telegram.login(Telegram.java:165)
          at at.nonon.telegram.telegram.Telegram.startApi(Telegram.java:105)
          at at.nonon.telegram.telegram.Telegram.&lt;init&gt;(Telegram.java:54)
          at at.nonon.telegram.telegram.ApiManager.startNew(ApiManager.java:21)
          at at.nonon.telegram.Moin.onApiStart(Moin.java:31)
  </code></pre>
  
  <p>I took alot of the Code from the telegram-bot (<a href="https://github.com/ex3ndr/telegram-bot" rel="noreferrer">https://github.com/ex3ndr/telegram-bot</a>) but even if I copy paste his Code, it still doesn't work...</p>
  
  <p>Thanks in Advance</p>