0
已经建立了一个SSL连接的应用程序,已经建立使用单线程客户端和服务器之间的连接。由于我的应用程序处理远程桌面访问,我试图执行线程。应用程序只是在使用线程时挂起?
不知道为什么应用程序只是在创建套接字后停止,它既没有失败也没有执行SSLhandshake。在单线程下执行时的相同代码工作正常,但在多线程下则不行。已经尝试logcat,它无法帮助我。在10-15次尝试中,应用程序正常工作1次,但进入不响应模式。
任何想法,我打错了?这是代码。任何答案,请分享。
主要活动:
Thread t = new Thread() {
public void run() {
try{
Log.d(TAG, "Opening RFB socket");
rfb = new rfbProtocol(ip, port, RFB_ClientActivity.getContext());
txt_notify.append("Connection done");
Log.d(TAG, "RFB socket openned");
handler.post(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
progress.setMessage("Connection established..\nPlease wait");
}
});
processProtocol(progress);
}catch(Exception e){
if(maintainConnection){
if(progress.isShowing())
progress.dismiss();
txt_notify.append("Connection failure:\n" + e.getMessage());
Log.d(TAG,"RFB socket failure");
e.printStackTrace();
}
}
}
};
t.start();
rfbProtocol:
rfbProtocol(String h, int p, Context c) throws Exception {
// TODO Auto-generated constructor stub
host = h;
port = p;
cont = c;
try {
// Setup the SSL context to use the truststore and keystore
Log.d(TAG, "Initializing SSL connection");
SSLContext ssl_context = createSSLContext(cont);
SSLSocketFactory socketFactory = (SSLSocketFactory) ssl_context.getSocketFactory();
Log.d(TAG,"Creating RFB socket");
socket = (SSLSocket) socketFactory.createSocket(host, port);
Log.d(TAG,"RFB Socket created");
dataOut = socket.getOutputStream();
dataIn = new DataInputStream(new BufferedInputStream(socket.getInputStream(), 16384));
close = false;
Log.d(TAG,"SSL connection done");
} catch (Exception e) {
// TODO Auto-generated catch block
throw(e);
}
}
private SSLContext createSSLContext(final Context cont) throws Exception{
SSLContext ssl_cont = null;
try {
// Setup truststore
Log.d(TAG, "TrustStore - Initializing");
KeyStore trustStore = KeyStore.getInstance("BKS");
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
InputStream trustStoreStream = cont.getResources().openRawResource(R.raw.clienttruststore);
trustStore.load(trustStoreStream, "client".toCharArray());
trustManagerFactory.init(trustStore);
Log.d(TAG, "TrustStore - Initialized");
// Setup keystore
Log.d(TAG, "KeyStore - Initializing");
KeyStore keyStore = KeyStore.getInstance("BKS");
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
InputStream keyStoreStream = cont.getResources().openRawResource(R.raw.client);
keyStore.load(keyStoreStream, "client".toCharArray());
keyManagerFactory.init(keyStore, "client".toCharArray());
Log.d(TAG, "KeyStore - Initialized");
ssl_cont = SSLContext.getInstance("TLS");
ssl_cont.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null);
} catch (Exception e) {
// TODO Auto-generated catch block
throw(e);
}
return ssl_cont;
}
应用只是挂起后 “RFB插槽创建”,然后通过在logcat的意图登录活动。提前致谢。
你使用异步任务吗?如果不是值得去尝试。 – kosa 2012-04-19 19:57:57
@thinksteep:既没有帮助我:(这里是[日志文件](http://dl.dropbox.com/u/60536209/logcat.txt)我在Android 2.3上运行应用程序时,得到了应用程序对于android 2.2,我希望它不重要。:( – 2012-04-20 19:17:33
'我/ ActivityManager(159):开始:意图{act = android.intent.action.MAIN猫= [android.intent.category.LAUNCHER] flg = 0x10100000 cmp = com.rfb.client/.RFB_ClientActivity bnds = [182,205] [238,271]}来自pid 159' 这个东西在插座创建后出现,不是为什么,而是它的来临 – 2012-04-20 19:21:47