skip to Main Content

I have a Problem regarding the Telegram API
Whenever I do a RpcCall, it always give me a TimeoutException except when I do a NonAuth Call.

I can SignIn with a Number already and I set Authenticated to true in my AbsApiState and still can only do NonAuth Calls

Here is my 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();

}

And here the Error:

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.<init>(Telegram.java:54)
        at at.nonon.telegram.telegram.ApiManager.startNew(ApiManager.java:21)
        at at.nonon.telegram.Moin.onApiStart(Moin.java:31)

I took alot of the Code from the telegram-bot (https://github.com/ex3ndr/telegram-bot) but even if I copy paste his Code, it still doesn’t work…

Thanks in Advance

3

Answers


  1. this problem happened to me, too. I assume you are on a debian or some other linux box. The problem is Oracle JDK’s use of the linux random number generator.

    In order to make it work, run your application like this:

    java -Djava.security.egd=file:/dev/./urandom -jar foo.jar
    

    … meaning, you have to specify the java.security.egd parameter.

    Details can be found here: https://github.com/ex3ndr/telegram-api/issues/9#issuecomment-38175765
    and here:
    http://www.virtualzone.de/2011/10/javas-securerandomgenerateseed-on-linux.html

    Login or Signup to reply.
  2. It started working for me after I changed the server IP address in MemoryApiState as shown below

     public void start(boolean isTest) {
        connections = new HashMap<>();
        connections.put(1, new ConnectionInfo[]{
                new ConnectionInfo(1, 0, isTest ? "149.154.175.10" : "149.154.175.50", 443),
    
        });
    }
    
    Login or Signup to reply.
  3. Your timeout might happen for several reasons – please see my answer to
    TimeoutException on telegram java client

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search