我尝试使用Telegram Java API https://github.com/ardock/telegram-api 我从一些简单的RPC调用开始:
SampleApiState apiState = new SampleApiState(connections);
TLRequestAuthCheckPhone checkRequest = new TLRequestAuthCheckPhone("+1234567890");
TelegramApi api = new TelegramApi(apiState, new ApplicationInfo(),
new ApiCallback() {
@Override
public void onUpdatesInvalidated(TelegramApi api) {
// TODO Auto-generated method stub
Log.i(TAG, "onUpdatesInvalidated");
}
@Override
public void onAuthCancelled(TelegramApi api) {
// TODO Auto-generated method stub
Log.i(TAG, "onAuthCancelled");
}
@Override
public void onUpdate(TLAbsUpdates updates) {
// TODO Auto-generated method stub
Log.i(TAG, "onUpdate");
}
});
TLCheckedPhone checkedPhone = api.doRpcCall(checkRequest);
这是log:
11524-11580/com.example.tltest W/System.err﹕ java.net.SocketException: socket failed: EACCES (Permission denied)
11524-11580/com.example.tltest W/System.err﹕ at libcore.io.IoBridge.socket(IoBridge.java:576)
11524-11580/com.example.tltest W/System.err﹕ at java.net.PlainSocketImpl.create(PlainSocketImpl.java:201)
11524-11580/com.example.tltest W/System.err﹕ at java.net.Socket.checkOpenAndCreate(Socket.java:664)
11524-11580/com.example.tltest W/System.err﹕ at java.net.Socket.connect(Socket.java:808)
11524-11580/com.example.tltest W/System.err﹕ at org.telegram.mtproto.transport.PlainTcpConnection.<init>(PlainTcpConnection.java:32)
11524-11580/com.example.tltest W/System.err﹕ at org.telegram.mtproto.pq.Authorizer.doAuth(Authorizer.java:198)
11524-11580/com.example.tltest W/System.err﹕ at org.telegram.api.engine.TelegramApi$ConnectionThread.waitForDc(TelegramApi.java:842)
11524-11580/com.example.tltest W/System.err﹕ at org.telegram.api.engine.TelegramApi$ConnectionThread.run(TelegramApi.java:907)
11524-11588/com.example.tltest I/System.out﹕ api#1001#Uploader:UploadFileThread iteration
11524-11580/com.example.tltest W/System.err﹕ Caused by: libcore.io.ErrnoException: socket failed: EACCES (Permission denied)
11524-11580/com.example.tltest W/System.err﹕ at libcore.io.Posix.socket(Native Method)
11524-11580/com.example.tltest W/System.err﹕ at libcore.io.BlockGuardOs.socket(BlockGuardOs.java:181)
11524-11580/com.example.tltest W/System.err﹕ at libcore.io.IoBridge.socket(IoBridge.java:561)
11524-11580/com.example.tltest W/System.err﹕ ... 7 more
11524-11580/com.example.tltest I/System.out﹕ TransportRate:onConnectionFailure #1
11524-11580/com.example.tltest I/System.out﹕ TransportRate:Transport: #1 173.240.5.1:443 #1.0
11524-11580/com.example.tltest I/System.out﹕ TransportRate:tryConnection #1
连接失败后,它会反复尝试连接,但不是很成功。我无法找出原因以及如何解决这个问题。也许有人有同样的问题?非常感谢一些帮助)
答案 0 :(得分:1)
从您发布的例外情况来看,它似乎是一个Android应用程序,这是一个权限问题。
java.net.SocketException: socket failed: EACCES (Permission denied)
尝试将其添加到清单文件中:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />