Writing an Android app that communicates with a nodejs server using socket.io 1.3.5 with SSL using Nkzawa client 0.4.2. Everything works perfectly fine... until i try to use SSL. I keep getting "com.github.nkzawa.engineio.client.EngineIOException: xhr poll error" when using self-signed certificate.
Could not figure it out so i even tried using his sample server code found here http://ift.tt/1OSDcf2
It also uses his certificates and keys, although I had to convert his keystore.jks to a .bks using http://ift.tt/ywEz1R Android logs still gives me the same error string on the EVENT_CONNECT_ERROR type event. I just attempts to reconnect over and over again... Do I do something wrong?
Heres my android code
public int configureCommands() {
if(d_configureCommands)Log.e(Tag+"","ConfigureCommands() Enter");
try {
SSLContext ctx = createSSLContext();
IO.setDefaultSSLContext(ctx);
IO.Options opts = new IO.Options();
opts.forceNew = true;
opts.reconnection = true;
opts.secure = false;
opts.sslContext = ctx;
socket = IO.socket(PROTOCOL+ "://" + SERVER_IP + ":" + SERVER_PORT,opts);
if(socket == null){
Log.e("SOCKET IS NULL","SOCKET IS NULL");
return -1;
}
///////////////////////// INCOMING COMMANDS ///////////////////////////////////////
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() { //CONNECT
@Override
public void call(Object... args) {
if (d_EventConnect) Log.e(Tag , "Event_Connect Enter");
}
}).on(Socket.EVENT_DISCONNECT, new Emitter.Listener() { //DISCONNECT
@Override
public void call(Object... args) {
if (d_EventDisconnect) Log.e(Tag , "Event_Disconnect Enter");
}
})
...
}).on(Socket.EVENT_CONNECT_ERROR,new Emitter.Listener() {
@Override
public void call(Object... args) {
Log.e(Tag ,"Event Connect Errr "+ args[0].toString());
}
}).on(Socket.EVENT_RECONNECT_ATTEMPT, new Emitter.Listener() {
@Override
public void call(Object... args) {
Log.e(Tag ,"Event RECONNECT ATTEMPT"+ args[0].toString());
}
}).on(Socket.EVENT_CONNECT_TIMEOUT, new Emitter.Listener() {
@Override
public void call(Object... args) {
Log.e(Tag ,"Event Connect Time Out"+ args[0].toString());
}
}).on(Socket.EVENT_ERROR, new Emitter.Listener() {
@Override
public void call(Object... args) {
Log.e(Tag ,"Event Connect Time Out"+ args[0].toString());
}
});
} catch (URISyntaxException e) {
Log.e(Tag+"","URISyntaxException",e);
} catch (Exception e) {
Log.e(Tag, "Exception Connection Denied: ", e);
}
return 0;
}
...
public void Connect(){
if(d_Connect)Log.e(Tag, "Connect() + Enter");
socket.connect();
}
public void Disconnect(){
if(d_Disconnect)Log.e(Tag, "Disconnect() Enter");
socket.disconnect();
}
SSLContext createSSLContext() throws GeneralSecurityException, IOException {
KeyStore ks = KeyStore.getInstance("BKS");
ks.load(mContext.getResources().openRawResource(R.raw.keystore), "password".toCharArray());
KeyManagerFactory kmf = KeyManagerFactory.getInstance("X509");
kmf.init(ks, "password".toCharArray());
TrustManagerFactory tmf = TrustManagerFactory.getInstance("X509");
tmf.init(ks);
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
return sslContext;
}
The library catches the error and continues to execute.. attempting to reconnect indefinitely. I'm not even sure what xhr poll error even means, it is a generic error.
Aucun commentaire:
Enregistrer un commentaire