rubenlagus / TelegramApi

Java library to create Telegram Clients
MIT License
296 stars 108 forks source link

Every doRpcCall times out #51

Open Gintasz opened 6 years ago

Gintasz commented 6 years ago

This Telegram API is confusing, already wasted 2 days. Every doRpcCall I make throws TimeoutException. If I make request doRpcCallNonAuth, it does not time out. Here is the code:

apiState = new MemoryApiState(sessionFile);
api = new TelegramApi(apiState, new AppInfo(107508, "devicemodel", "systemversion", "appversion", "EN"), new ApiCallback() {
    @Override
    public void onAuthCancelled(TelegramApi api) {

    }

    @Override
    public void onUpdatesInvalidated(TelegramApi api) {

    }

    @Override
    public void onUpdate(TLAbsUpdates updates) {

    }
});

try {
    TLConfig config = api.doRpcCallNonAuth(new TLRequestHelpGetConfig());
    apiState.updateSettings(config);
} catch (RpcException e) {
    e.printStackTrace();
} catch (TimeoutException e) {
    e.printStackTrace();
}

////// SIGN UP NEW USER

String phoneCodeHash = sendCode(phoneNumber.phoneNumber);
if(phoneCodeHash == null)
{
    System.out.println("ERROR SENDING SMS");
    throw new Exception("ERROR SENDING SMS");
}

// read phone code from sms
String phoneCode = null;
long beginTime = System.currentTimeMillis();
while(phoneCode == null)
{
    Thread.sleep(5000);
    phoneCode = smsApi.getMessage(phoneNumber.orderId);

    if(System.currentTimeMillis() - beginTime > 4 * 60 * 1000)
        throw new Exception("sms timeout");
}

// register user

TLRequestAuthSignUp signUp = new TLRequestAuthSignUp();
signUp.setFirstName(firstName);
signUp.setLastName(lastName);
signUp.setPhoneCode(phoneCode);
signUp.setPhoneCodeHash(phoneCodeHash);
signUp.setPhoneNumber(phoneNumber.phoneNumber);
TLAuthorization authorization = api.doRpcCallNonAuth(signUp, 10000, apiState.getPrimaryDc());
apiState.doAuth(authorization);

/// HERE IS THE FIRST REQUEST WITH DORPCCALL

TLRequestAccountUpdateUsername updateUsername = new TLRequestAccountUpdateUsername();
updateUsername.setUserName(username);
try {
    api.doRpcCall(updateUsername, 10000); // TIME OUT EXCEPTION
} catch (IOException e) {
    e.printStackTrace();
} catch (TimeoutException e) {
    e.printStackTrace();
}

I've added -Djava.security.egd=file:/dev/./urandom to VM options, but still does not work. I think something might be wrong with authentication, but I have no idea what

unoexperto commented 6 years ago

@Gintasz Yeah, I'm in the same boat. Any progress on your side ? Overall codebase is of impressively bad quality - zero documentation, zero comments, naming of interfaces and class with Borland Delphi style. I'm still digging through it and will report if I build minimal working client.

sadeghpro commented 6 years ago

Did you use Deepthought sample? I use that sample and modify it in a 6-7 project and its work without any timeout. yes, it's no comment if you download Javadoc you only find a name of the function in Javadoc and some other thing but work correctly. I found some bug and I can resolve some of them. I told everyone in this repository to start from Deepthought sample but I don't know why some body doesn't use it.

mdhak83 commented 4 years ago

I'm trying to take over from Ruben's code here : https://github.com/mdhak83/javaGram Any help appreciated !