Open ashokcoolguys opened 9 years ago
Hi ...thank u very much for the reference...but i am getting these exception in windows 7 64bit os with jdk1.7 Any clues on this... On Dec 2, 2014 7:08 PM, "Alex Kvak" notifications@github.com wrote:
See this solution for linux #9 https://github.com/ex3ndr/telegram-api/issues/9#issuecomment-38175765
— Reply to this email directly or view it on GitHub https://github.com/ex3ndr/telegram-api/issues/30#issuecomment-65231242.
Do you switch DC after code confirmation?
no
@alexkvak , I am using the same DC. Not able to get the list of DCs available.Also,can u share me some idea that how you are transforming the methods(like help.getConfig#c4f9186b) specified in telegram's website to Java or any other programming language
def switchToNearestDc() = {
val dcInfo = api.doRpcCallNonAuth(new TLRequestHelpGetNearestDc)
api.switchToDc(dcInfo.getNearestDc)
}
Hi Alex, Thanks for your time. I ve tried the method u've specified ..Thanks again. But Am getting null pointer exception ,which is generated in the ActorSystem class ..
Test Code::
TLNearestDc neardc=api.doRpcCallNonAuth( new TLRequestHelpGetNearestDc()); System.out.println("Nearest DC"+neardc.getNearestDc()+" "+neardc.getCountry()+" "+neardc.getThisDc()+" "); api.switchToDc(neardc.getNearestDc());
Log:: Nearest DC2 IN 2 Exception in thread "main" java.lang.NullPointerException at org.telegram.actors.ActorSystem.close(ActorSystem.java:97) at org.telegram.mtproto.MTProto.close(MTProto.java:221) at org.telegram.api.engine.TelegramApi.switchToDc(TelegramApi.java:161) at testmsg.Testmsg.main(Testmsg.java:188)
ActorSystem.java--(....where exception is thrown)
public void close() { for (int i = 0; i < holdersCount; i++) { if (holders[i].actorThread != null) { holders[i].actorThread.close(); } } }
On Wed, Dec 3, 2014 at 3:35 PM, Alex Kvak notifications@github.com wrote:
def switchToNearestDc() = { val dcInfo = api.doRpcCallNonAuth(new TLRequestHelpGetNearestDc) api.switchToDc(dcInfo.getNearestDc) }
— Reply to this email directly or view it on GitHub https://github.com/ex3ndr/telegram-api/issues/30#issuecomment-65383150.
Do you do TLRequestHelpGetConfig request?
Yes I have tried this to get the DC Options.
TLConfig TLCCC=api.doRpcCallNonAuth( new TLRequestHelpGetConfig());
TLVector
I tried switching DC with and without using the above code.
On Thu, Dec 4, 2014 at 1:32 AM, Alex Kvak notifications@github.com wrote:
Do you do TLRequestHelpGetConfig request?
— Reply to this email directly or view it on GitHub https://github.com/ex3ndr/telegram-api/issues/30#issuecomment-65478917.
Tell me, what you also do before this code?
I switch DC after this code.. I can advice you to log nearestDC value and changes of currentDC value
can you wrap your code as source code? See markdown documentation
@alexkvak ,Code in required format
public class Testmsg {
private static Random rnd = new Random();
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException{
AppInfo appinfo=new AppInfo(APP_ID, "TestApp", "???", "???","en");
//int apiId, String deviceModel, String systemVersion, String appVersion, String langCode
//TLRequestAuthCheckPhone checkRequest = new TLRequestAuthCheckPhone("8939675043");
MyApiStorage state=new MyApiStorage();
TelegramApi api = new TelegramApi(state, appinfo, new ApiCallback()
{
public void onApiDies(TelegramApi api) {
// When auth key or user authorization dies
}
@Override
public void onUpdatesInvalidated(TelegramApi api) {
// When api engine expects that update sequence might be broken
}
@Override
public void onAuthCancelled(TelegramApi ta) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void onUpdate(TLAbsUpdates updates) {
System.out.println("user Id ::::"+((TLUpdateShortMessage) updates).getFromId());
// if (updates instanceof TLUpdateShortMessage) {
// onIncomingMessageUser(
// ((TLUpdateShortMessage) updates).getFromId(),
// ((TLUpdateShortMessage) updates).getMessage());
// } else if (updates instanceof TLUpdateShortChatMessage) {
// onIncomingMessageChat(
// ((TLUpdateShortChatMessage) updates).getFromId(),
// ((TLUpdateShortChatMessage) updates).getChatId(),
// ((TLUpdateShortChatMessage) updates).getMessage());
// }
//To change body of generated methods, choose Tools | Templates.
}
});
//TLCheckedPhone checkedPhone = api.doRpcCall(checkRequest);
//checkedPhone.setPhoneRegistered(true);
//System.out.println(api.toString());
//TLConfig config = api.doRpcCallNonAuth(new TLRequestHelpGetConfig());
// state.updateSettings(config);
TLSentCode sentCode;
String phone ="+919999988888";
//sentCode = api.doRpcCallNonAuth(new TLRequestAuthSendCode(phone, 0,5, "APP_ID", "en"));
try {
sentCode = api.doRpcCallNonAuth(new TLRequestAuthSendCode(phone, 0, APP_ID, APP_HASH, "en"));
} catch (RpcException e) {
if (e.getErrorCode() == 303) {
int destDC;
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 {
throw e;
}
api.switchToDc(destDC);
sentCode = api.doRpcCallNonAuth(new TLRequestAuthSendCode(phone, 0, APP_ID, APP_HASH, "en"));
} else {
throw e;
}
}
BufferedReader reader = new BufferedReader(new InputStreamReader(
System.in));
//String code ="12533";
System.out.println("PDC:::::"+state.getPrimaryDc());
System.out.println("MTPROSTAT"+state.getMtProtoState(state.getPrimaryDc()));
System.out.println("EnterCode::");
String code = reader.readLine();
// System.out.println("state before auth"+state.isAuthenticated(state.getPrimaryDc()));
TLAuthorization auth = api.doRpcCallNonAuth(new TLRequestAuthSignIn(
phone, sentCode.getPhoneCodeHash(),code));
//state.setAuthenticated(state.getPrimaryDc(), true);
// System.out.println("state after auth"+state.isAuthenticated(state.getPrimaryDc()));
//state.setAuthenticated(state.getPrimaryDc(), true);
// TLContacts tlcont=new TLContacts();
// TLVector<TLAbsUser> tlauser=tlcont.getUsers();
// TLVector<TLContact> a = null;
// a.add(1, new TLContact(12345,true));
System.out.println("Expiry:"+auth.getExpires());
TLInputContact tlic=new TLInputContact(100101, PH_NO, "Guhan", "K");
System.out.println("Phone Number"+tlic.getPhone());
TLVector<TLInputContact> contacts = new TLVector<>();
contacts.add(tlic);
TLRequestContactsImportContacts importContacts = new TLRequestContactsImportContacts(contacts, true);
///System.out.println("Contact:::"+ importContacts.toString());
/// TLContacts CCC=api.doRpcCallNonAuth(new TLRequestContactsGetContacts("Guhan"));
// System.out.println(CCC.;
TLNearestDc neardc=api.doRpcCallNonAuth( new TLRequestHelpGetNearestDc());
System.out.println("Nearest DC"+neardc.getNearestDc()+" "+neardc.getCountry()+" "+neardc.getThisDc()+" ");
//TLConfig TLCCC=api.doRpcCallNonAuth( new TLRequestHelpGetConfig());
//TLVector<TLDcOption> TLCC_DC=TLCCC.getDcOptions();
//state.updateSettings(TLCCC);
//api.getState().setPrimaryDc(TLCCC.getThisDc());
//i)
api.switchToDc(neardc.getNearestDc());
// TLConfig TLCCC=api.doRpcCallNonAuth( new TLRequestHelpGetConfig());
// TLVector<TLDcOption> TLCC_DC=TLCCC.getDcOptions();
// for(int i=0;i<TLCC_DC.size();i++)
// {
// System.out.println( TLCC_DC.get(i).getHostname()+" "+TLCC_DC.get(i).getIpAddress()+" "+TLCC_DC.get(i).getPort());
// }
// state.updateSettings(TLCCC);
// System.out.println(state.getPrimaryDc()+"AAAAAAAAAAAASSSSSSSSSSDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD");
// api.switchToDc(state.getPrimaryDc());
try
{
// api.getState().updateSettings(TLCCC);
// System.out.println(api.getState().getAvailableConnections(1)[0].getId()+"AAAAAAAAAAAASSSSSSSSSSDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD");
// api.getState().setPrimaryDc(api.getState().getAvailableConnections(1)[0].getId());
// state.setPrimaryDc(api.getState().getPrimaryDc());
TLImportedContacts importedContacts = api.doRpcCall(importContacts);
System.out.println("Time1::::::::::"+System.currentTimeMillis());
//auth.setUser(null);
// api.doRpcCall(importContacts,30000,new RpcCallback(){
//
// @Override
// public void onResult(TLObject t) {
// System.out.println("Done::::::::::");
// TLImportedContacts importedContacts=(TLImportedContacts) t;//To change body of generated methods, choose Tools | Templates.
//
// }
//
// @Override
// public void onError(int i, String string) {
// System.out.println("Time1::::::::::"+System.currentTimeMillis());
// System.out.println("Error::::::::::"+i+string);
// }
// });
TLAbsUser recipient=importedContacts.getUsers().get(0);
TLInputPeerContact peer = new TLInputPeerContact(recipient.getId());
TLRequestMessagesSendMessage sendMessageRequest = new TLRequestMessagesSendMessage(peer, "Test", rnd.nextInt());
TLAbsSentMessage sentMessage = api.doRpcCall(sendMessageRequest);
}
catch(Exception eee)
{
System.out.println("A::::::::::"+eee);
}
// TLContacts tlcont=new TLContacts();
// tlcont.setContacts(a);
// System.out.println("User list"+tlauser.toString());
// TLVector<TLContact> tlvc;
// TLVector<TLAbsUser> tlauser;
// TLContacts contact=new TLContacts(tlvc,tlauser);
// System.out.println("Contact***"+contact.getContacts().toString());
//TLState tlstate = api.doRpcCall(new TLRequestUpdatesGetState());
//TLCheckedPhone checkedPhone = api.doRpcCall(checkRequest);
//TLInputPeerContact a=new TLInputPeerContact();
// TLRequestContactsGetContacts contactsget=new TLRequestContactsGetContacts("Gughan Tools");
//api.doRpcCall()
/*
api.doRpcCall(new TLRequestMessagesSendMessage(new TLInputPeerContact(111234), "test", rnd.nextInt()), 15 * 60000,
new RpcCallbackEx<TLAbsSentMessage>() {
@Override
public void onConfirmed() {
}
@Override
public void onResult(TLAbsSentMessage result) {
}
@Override
public void onError(int errorCode, String message) {
System.out.println("Error in sending"+errorCode+" "+message);
}
});*/
//TLState tlsstate = api.doRpcCall(new TLRequestUpdatesGetState());
//System.out.println("TLState"+tlsstate.toString());
}
}
My app does so:
TLConfig config = api.doRpcCallNonAuth(new TLRequestHelpGetConfig());
state.updateSettings(config);
then
switchToNearestDc();
then
// TLRequestAuthSendCode
Tried this way also..Still getting same NullPointerException
Exception Exception in thread "main" java.lang.NullPointerException TelegramApi#1001:<< #1 nearestDc#8e1a1775 in 180 ms MTProto#1001#Scheduller:Forgetting message: #20 at org.telegram.actors.ActorSystem.close(ActorSystem.java:97) at org.telegram.actors.ActorSystem.close(ActorSystem.java:97) at org.telegram.mtproto.MTProto.close(MTProto.java:221) at org.telegram.api.engine.TelegramApi.switchToDc(TelegramApi.java:161) at testmsg.Testmsg.main(Testmsg.java:124)
Code Changes::
.....
TLConfig config = api.doRpcCallNonAuth(new TLRequestHelpGetConfig()); state.updateSettings(config); TLNearestDc neardc=api.doRpcCallNonAuth( new TLRequestHelpGetNearestDc()); api.switchToDc(neardc.getNearestDc()); TLSentCode sentCode; String phone ="+919999988888"; try { sentCode = api.doRpcCallNonAuth(new TLRequestAuthSendCode(phone, 0, 19815, "19e19d5ce8ce398b828202f7cdc9f76c", "en")); } catch (RpcException e) { ......
On Thu, Dec 4, 2014 at 4:44 PM, Alex Kvak notifications@github.com wrote:
My app does so:
TLConfig config = api.doRpcCallNonAuth(new TLRequestHelpGetConfig()); state.updateSettings(config);
then
switchToNearestDc();
then
// TLRequestAuthSendCode
— Reply to this email directly or view it on GitHub https://github.com/ex3ndr/telegram-api/issues/30#issuecomment-65617553.
so the problem is in you nearest dc. What is it address? By the way, did you debug the updateSettings method? It should update api's connections
My nearest server is dc2 in (india)[will share u the ip].. I ve debugged the update setting method ,there the connections were updated.. On Dec 4, 2014 9:00 PM, "Alex Kvak" notifications@github.com wrote:
so the problem is in you nearest dc. What is it address? By the way, did you debug the updateSettings method? It should update api's connections
— Reply to this email directly or view it on GitHub https://github.com/ex3ndr/telegram-api/issues/30#issuecomment-65648653.
show me the updateSetting method code
Specified entire API Storage class (implement AbsApiState) below package testmsg; import java.util.ArrayList; import java.util.HashMap;
import org.telegram.api.TLConfig;
import org.telegram.api.TLDcOption;
import org.telegram.api.engine.storage.AbsApiState;
import org.telegram.mtproto.state.AbsMTProtoState;
import org.telegram.mtproto.state.ConnectionInfo;
import org.telegram.mtproto.state.KnownSalt;
//import org.telegram.mtproto.pq.Authorizer;
public class MyApiStorage implements AbsApiState {
private HashMap<Integer, ConnectionInfo[]> connections = new HashMap<Integer, ConnectionInfo[]>();
private HashMap<Integer, byte[]> keys = new HashMap<Integer, byte[]>();
private HashMap<Integer, Boolean> isAuth = new HashMap<Integer, Boolean>();
private int primaryDc = 1;
public MyApiStorage() {
connections.put(1, new ConnectionInfo[]{
new ConnectionInfo(1, 0, "149.154.167.40", 443) // Test
//new ConnectionInfo(1, 0, "173.240.5.1", 443) // Production
});
// Authorizer a=new Authorizer(); a.doAuth(connections.get(1));
}
@Override
public byte[] getAuthKey(int dcId) {
return keys.get(dcId);
}
@Override
public ConnectionInfo[] getAvailableConnections(int dcId) {
if (!connections.containsKey(dcId)) {
return new ConnectionInfo[0];
}
return connections.get(dcId);
}
@Override
public AbsMTProtoState getMtProtoState(final int dcId) {
return new AbsMTProtoState() {
private KnownSalt[] knownSalts = new KnownSalt[0];
@Override
public byte[] getAuthKey() {
return MyApiStorage.this.getAuthKey(dcId);
}
@Override
public ConnectionInfo[] getAvailableConnections() {
return MyApiStorage.this.getAvailableConnections(dcId);
}
@Override
public KnownSalt[] readKnownSalts() {
return knownSalts;
}
@Override
protected void writeKnownSalts(KnownSalt[] salts) {
knownSalts = salts;
}
};
}
@Override
public int getPrimaryDc() {
return primaryDc;
}
@Override
public boolean isAuthenticated(int dcId) {
if (isAuth.containsKey(dcId)) {
return isAuth.get(dcId);
}
return false;
}
@Override
public void putAuthKey(int dcId, byte[] key) {
keys.put(dcId, key);
}
@Override
public void reset() {
isAuth.clear();
keys.clear();
}
@Override
public void resetAuth() {
isAuth.clear();
}
@Override
public void setAuthenticated(int dcId, boolean auth) {
isAuth.put(dcId, auth);
}
@Override
public void setPrimaryDc(int dc) {
primaryDc = dc;
}
@Override
public void updateSettings(TLConfig config) {
connections.clear();
HashMap<Integer, ArrayList<ConnectionInfo>> tConnections = new HashMap<Integer, ArrayList<ConnectionInfo>>();
int id = 0;
// System.out.println("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
for (TLDcOption option : config.getDcOptions()) {
// System.out.println("BBBBBBBBBBBBBBBBBBBBBB");
if (!tConnections.containsKey(option.getId())) {
// System.out.println("CCCCCCCCCCCCCCCCCCCCCCCCCCCc"+option.getId());
tConnections.put(option.getId(), new ArrayList<ConnectionInfo>());
}
tConnections.get(option.getId()).add(new ConnectionInfo(id++, 0, option.getIpAddress(), option.getPort()));
}
for (Integer dc : tConnections.keySet()) {
connections.put(dc, tConnections.get(dc).toArray(new ConnectionInfo[0]));
}
}
}
Did you see, how it's implemented in Telegram for Android? Maybe here is some mistake
Hi I had the same problem and I fix updating the JDK of my Linux and changing the java.security file
securerandom.source=file:/dev/./urandom
Am facing this issue in windows..
On Sun, Dec 21, 2014 at 1:21 AM, Victor de la Cruz <notifications@github.com
wrote:
Hi I had the same problem and I fix updating the JDK of my Linux and changing the java.security file
securerandom.source=file:/dev/urandom
securerandom.source=file:/dev/./urandom
— Reply to this email directly or view it on GitHub https://github.com/ex3ndr/telegram-api/issues/30#issuecomment-67747459.
Hello, I want to use api telegram for android and I want to know about what operating system works correctly because I'm using windows 7 64 bit and eclipse and timeout exception for rpc call occurs. Help please! :(
I have got the same problem on windows 7 64bit. the timeout is only occur for RPC calls. and if I add "securerandom.source=file:/dev/./urandom" to java.security. the program even not able to connect to the DC . so right now the step is :
I had to change ip address for telegram server in ApiState
Exactly... On Mar 5, 2015 12:25 AM, "9CAT" notifications@github.com wrote:
I have got the same problem on windows 7 64bit. the timeout is only occur for RPC calls. and if I add "securerandom.source=file:/dev/./urandom" to java.security. the program even not able to connect to the DC . so right now the step is :
- fetch DC
- ask phone number
- ask auth code
- done and wait
- timeout come up. 6 and actordispatcher:dispatching action: schedue for scheduller.
- then nothing is working, not monitoring any incoming message too.
— Reply to this email directly or view it on GitHub https://github.com/ex3ndr/telegram-api/issues/30#issuecomment-77220893.
It started working for me after I updated Server IP Address in the MemoryStateAPI class, 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)
});
}
How can i get all contact list for my telegram application? I register new app in https://my.telegram.org/apps. I looked and I was too tired....:(
Munish,Pls share your working code. I ll try from my environment.I am assuming that there is some problem with my development environment ( Windows 7/2008 server 64 bit)
Regards Ashok Natarajan
On Sat, Aug 8, 2015 at 1:21 AM, mohammad ghasemi notifications@github.com wrote:
How can i get all contact list for my telegram application? I register new app in https://my.telegram.org/apps. I looked and I was too tired....:(
— Reply to this email directly or view it on GitHub https://github.com/ex3ndr/telegram-api/issues/30#issuecomment-128811333.
I am trying to add and import a contact for sending message.but i am getting time out exception every time. Correct me if something wrong.
Code:
TLInputContact tlic=new TLInputContact(1, PhNo, Fname, Lname); TLVector contacts = new TLVector<>();
contacts.add(tlic);
TLRequestContactsImportContacts importContacts = new TLRequestContactsImportContacts(contacts, true);
TLImportedContacts importedContacts = api.doRpcCall(importContacts);
TLAbsUser recipient=importedContacts.getUsers().get(0);
TLInputPeerContact peer = new TLInputPeerContact(recipient.getId());
TLRequestMessagesSendMessage sendMessageRequest = new TLRequestMessagesSendMessage(peer, "Test", rnd.nextInt());
TLAbsSentMessage sentMessage = api.doRpcCall(sendMessageRequest);
Log:: TelegramApi#1001:Timeout Iteration ActorDispatcher:Dispatching action: schedule for scheduller ActorDispatcher:Dispatching action: schedule for scheduller TelegramApi#1001:Timeout Iteration TelegramApi#1001:RPC #3: Timeout (15001 ms) Exception in thread "main" 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 testmsg.Testmsg.main(Testmsg.java:151) TelegramApi#1001:Timeout Iteration