Comments (28)
i have the same Problem. I have created a self-sigend certifcate but socketio won't connect to my server...
When i listen to the "EVENT_CONNECT_ERROR" Event i get the following ErrorMessage:
"com.github.nkzawa.engineio.client.EngineIOException: xhr poll error"
------------- ServerCode ( Snippet ) -------------
express = require('express'),
app = express(),
https = require('https').createServer({
key: fs.readFileSync('server.key'),
cert: fs.readFileSync('server.crt'),
ca: fs.readFileSync('server.csr'),
}, app);
io = require('socket.io')(https);
https.listen(config.port, function() {
console.log('Listening on Port %d', config.port);
});
Java-Client:
IO.Options options = new IO.Options();
try {
options.sslContext = createSSLContext();
} catch (GeneralSecurityException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
options.secure = true;
TokenManager tokenManager = new TokenManager();
String token = tokenmanager.getToken();
socket = IO.socket(Globals.HOST + "/?token=" + token, options);
socket.on(socket.EVENT_CONNECT, new Emitter.Listener() {
@Override
public void call(Object... args) {
Log.d("SOCKETIO", "CONNECTED");
startMessageListener(socket);
}
});
public SSLContext createSSLContext() throws GeneralSecurityException, IOException {
Security.insertProviderAt(new BouncyCastleProvider(), 1);
try {
TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
@Override
public void checkClientTrusted(X509Certificate[] certs, String authType) {
}
@Override
public void checkServerTrusted(X509Certificate[] certs, String authType) {
}
}
// Install the all-trusting trust manager
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
return sc;
} catch (Exception exception) {
exception.printStackTrace();
}
return null;
}
If i use this code for http-Requets everything works fine
from socket.io-client-java.
I cause the problem, just use code
When "io.socket.engineio.client.EngineIOException: xhr poll error" is appeared,for I use emit method's second param is String not JSONObject.
Connect to socket.io server use java api caused me one day! O my god.
from socket.io-client-java.
Umm, I'm not sure what the problem is, but it may be helpful to compare with my settings for unit tests.
Set the log level FINE
or lower to see all logs.
from socket.io-client-java.
I think the problem is maybe related to host name verification. Try to set the
HttpsURLConnection.setDefaultHostnameVerifier(new RelaxedHostNameVerifier());
...
public static class RelaxedHostNameVerifier implements HostnameVerifier {
public boolean verify(String hostname, SSLSession session) {
return true;
}
}
Unfortunality such exceptions are not logged. I suggest to add logging at Request.onError including the exception stack.
Maybe you can add the HostNameVerified as additional Option too.
from socket.io-client-java.
Hello, I'm using this library too for connecting to server. Connection to server is secured too.
But in my case I creates SSLContext which should accept all certificates like this:
private TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new java.security.cert.X509Certificate[] {};
}
public void checkClientTrusted(X509Certificate[] chain,
String authType) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] chain,
String authType) throws CertificateException {
}
} };
public static class RelaxedHostNameVerifier implements HostnameVerifier {
public boolean verify(String hostname, SSLSession session) {
return true;
}
}
and in code I set it up:
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null, trustAllCerts, new SecureRandom());
IO.setDefaultSSLContext(sc);
HttpsURLConnection.setDefaultHostnameVerifier(new RelaxedHostNameVerifier());
and I create custom IO.Options:
IO.Options options = new IO.Options();
options.sslContext = sc;
options.secure = true;
options.port = 443;
and for establishing connection I use this code, maybe very similar as the code from samples:
Socket socket = IO.socket("https://before.host.com", options);
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override
public void call(Object... args) {
Log.d(TAG, "eventConnect");
}
}).on(Socket.EVENT_MESSAGE, new Emitter.Listener() {
@Override
public void call(Object... args) {
Log.d(TAG, "eventMessage");
}
}).on(Socket.EVENT_DISCONNECT, new Emitter.Listener() {
@Override
public void call(Object... args) {
Log.d(TAG, "eventDisconnect");
}
}).on(Socket.EVENT_CONNECT_ERROR, new Emitter.Listener() {
@Override
public void call(Object... args) {
Log.d(TAG, "eventConnectError");
for(Object o : args){
Log.d(TAG, "object: " + o.toString());
if(o instanceof SocketIOException)
((SocketIOException) o).printStackTrace();
}
}
}).on(Socket.EVENT_ERROR, new Emitter.Listener() {
@Override
public void call(Object... args) {
Log.d(TAG, "eventError");
}
});
socket.connect();
And this instantly gives me an Exception, the same as in previous cases:
com.github.nkzawa.engineio.client.EngineIOException: xhr poll error
And if I create my own server app, unsecured with scheme - http, on my private network, everything works. Is it problem on client side (me) or server side?
Thank you for your advices!
from socket.io-client-java.
How about https connect?
from socket.io-client-java.
Hi @feromakovi and @crossle I was able to communicate from my android phone via ssl. Here it is the project I setup for you guys to try it out.
https://github.com/jonathanve/socket-io-android
Hope it helps.
from socket.io-client-java.
I wrote the code inside my application class. Anywhere else where should I locate it instead?
from socket.io-client-java.
@nkzawa ?
from socket.io-client-java.
@jonathanve what's your problem?
from socket.io-client-java.
@jonathanve btw, thank you for your great example app 👍
from socket.io-client-java.
hi @nkzawa , thank you. Hope the example helps somebody so this issue can be closed
from socket.io-client-java.
how to handle for "https" connections?
from socket.io-client-java.
Hello,
I'm also trying to use https connection on my Android client but I get either the dreaded xhr poll error on JellyBean+ or a strange semi working behaviour on Gingerbread or IceCreamSandwich.
I've running on a Raspberry Pi a simple node.js app that runs Express to serve a webpage embedded with the client side socket.io script.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="/socket.io/socket.io.js"></script>
</head>
<body>
<h1>Content of the document</h1>
<script>
var div = document.createElement('div');
var socket = io.connect('https://raspberrypi/');
socket.on('secure_data', function(secure_data) {
console.log(secure_data);
var p = document.createElement('p');
p.appendChild(document.createTextNode('' + secure_data));
document.body.appendChild(p);
});
</script>
</body>
</html>
and with the https server app
var fs = require('fs');
var https = require('https');
var express = require('express');
var socketio = require('socket.io');
var port = 443;
var app = express();
var server = https.createServer({
key: fs.readFileSync('server.key'),
cert: fs.readFileSync('server.crt')
}, app).listen(port, function() {
console.log('Listening on *:' + port);
});
app.use(express.static(__dirname + '/public'));
var io = socketio(server);
io.on('connection', function(socket) {
setInterval(function() {
socket.emit('secure_data', { hello: 'secure_world' });
}, 1000);
});
I'm generating the keys and ca with a script via openssl
#!/bin/bash
openssl genrsa -des3 -passout pass:x -out server.pass.key 2048
openssl rsa -passin pass:x -in server.pass.key -out server.key
rm server.pass.key
# When the openssl req command asks for a "challenge password",
# just press return, leaving the password empty.
openssl req -new -key server.key -out server.csr
# Generate SSL certificate.
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
then I copied the .crt file to my Android Studio project and tried to load the self signed certificate as mentioned in the docs of Android.
https://developer.android.com/training/articles/security-ssl.html#UnknownCa
private void getSocketIO() {
final String uri = "https://raspberrypi/";
try {
// Load CAs from an InputStream.
CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
Certificate certificate = certificateFactory.generateCertificate(
getResources().openRawResource(R.raw.server)); // from file server.crt
// Create a KeyStore containing the trusted CAs.
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
keyStore.load(null, null);
keyStore.setCertificateEntry("ca", certificate);
// Create a TrustManager that trusts the CAs in KeyStore.
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(
TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(keyStore);
// Create an SSLContext that uses the TrustManager.
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustManagerFactory.getTrustManagers(), null);
Log.i(uri, "sslContext created");
//
// Try to open url.
URL url = new URL(uri);
final HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url.openConnection();
httpsURLConnection.setSSLSocketFactory(sslContext.getSocketFactory());
httpsURLConnection.setHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
Log.i("HostnameVerifier", "Approving certificate for " + hostname);
return true; // Do nothing.
}
});
new Thread(new Runnable() {
@Override
public void run() {
try {
BufferedReader in = new BufferedReader(new InputStreamReader(
httpsURLConnection.getInputStream()));
Log.i("httpsURLConnection", "url connected");
String line; //FIXME: readLine kicks in socket.io at least on gingerbread!?
while((line = in.readLine()) != null) {
Log.i("httpsURLConnection", line);
}
in.close();
} catch (IOException e) {
}
}
}).start();
//
// Try to use socket.io library.
IO.setDefaultSSLContext(sslContext);
IO.Options options = new IO.Options();
options.secure = true;
options.sslContext = sslContext;
Socket socket = IO.socket(uri, options);
socket.on(Socket.EVENT_CONNECT_ERROR, new Emitter.Listener() {
@Override
public void call(Object... args) {
for(Object o : args) {
Log.i("IO " + Socket.EVENT_CONNECT_ERROR, o.toString());
}
}
}).on(Socket.EVENT_CONNECT_TIMEOUT, new Emitter.Listener() {
@Override
public void call(Object... args) {
Log.i("IO", Socket.EVENT_CONNECT_TIMEOUT);
}
}).on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override
public void call(Object... args) {
Log.i("IO", Socket.EVENT_CONNECT);
}
}).on("secure_data", new Emitter.Listener() {
@Override
public void call(Object... args) {
Log.i("IO secure_data", args[0].toString());
}
});
socket.connect();
} catch (Exception e) {
e.printStackTrace();
}
}
First thing was to add
<uses-permission android:name="android.permission.INTERNET"/>
in the manifest file.
To be sure that the certificate part was working I added the code to open a https connection and I printed out in the log the content of the html file. That worked fine without problems. But in the part of your socket.io library I got only "com.github.nkzawa.engineio.client.EngineIOException: xhr poll error" at least from JellyBean till Lollipop.
In another way Gingebread and ICS had a different behaviour: the socket.io library connected to the server without problems but only if I left the code inplace that was reading from the https input stream.
My wild guess would be that the javascript inside from the html file gets executed in some way and then kicks in the java socket.io library!?
I'm attaching the logs that I made:
From JellyBean till Lollipop
01-14 16:14:22.716 2654-2654/it.js.ssocketio I/https://raspberrypi/﹕ sslContext created
...
01-14 16:14:22.900 2654-2669/it.js.ssocketio I/HostnameVerifier﹕ Approving certificate for raspberrypi
...
01-14 16:14:23.022 2654-2678/it.js.ssocketio I/IO connect_error﹕ com.github.nkzawa.engineio.client.EngineIOException: xhr poll error
01-14 16:14:23.027 2654-2669/it.js.ssocketio I/httpsURLConnection﹕ url connected
01-14 16:14:23.292 2654-2669/it.js.ssocketio I/httpsURLConnection﹕ <!DOCTYPE html>
01-14 16:14:23.292 2654-2669/it.js.ssocketio I/httpsURLConnection﹕ <html>
01-14 16:14:23.292 2654-2669/it.js.ssocketio I/httpsURLConnection﹕ <head>
01-14 16:14:23.292 2654-2669/it.js.ssocketio I/httpsURLConnection﹕ <meta charset="UTF-8">
01-14 16:14:23.292 2654-2669/it.js.ssocketio I/httpsURLConnection﹕ <title>Title</title>
01-14 16:14:23.292 2654-2669/it.js.ssocketio I/httpsURLConnection﹕ <script src="/socket.io/socket.io.js"></script>
01-14 16:14:23.292 2654-2669/it.js.ssocketio I/httpsURLConnection﹕ </head>
01-14 16:14:23.292 2654-2669/it.js.ssocketio I/httpsURLConnection﹕ <body>
01-14 16:14:23.292 2654-2669/it.js.ssocketio I/httpsURLConnection﹕ <h1>Content of the document</h1>
01-14 16:14:23.292 2654-2669/it.js.ssocketio I/httpsURLConnection﹕ <script>
01-14 16:14:23.292 2654-2669/it.js.ssocketio I/httpsURLConnection﹕ var div = document.createElement('div');
01-14 16:14:23.292 2654-2669/it.js.ssocketio I/httpsURLConnection﹕ var socket = io.connect('https://raspberrypi/');
01-14 16:14:23.292 2654-2669/it.js.ssocketio I/httpsURLConnection﹕ socket.on('secure_data', function(secure_data) {
01-14 16:14:23.292 2654-2669/it.js.ssocketio I/httpsURLConnection﹕ console.log(secure_data);
01-14 16:14:23.292 2654-2669/it.js.ssocketio I/httpsURLConnection﹕ var p = document.createElement('p');
01-14 16:14:23.292 2654-2669/it.js.ssocketio I/httpsURLConnection﹕ p.appendChild(document.createTextNode('' + secure_data));
01-14 16:14:23.292 2654-2669/it.js.ssocketio I/httpsURLConnection﹕ document.body.appendChild(p);
01-14 16:14:23.292 2654-2669/it.js.ssocketio I/httpsURLConnection﹕ });
01-14 16:14:23.292 2654-2669/it.js.ssocketio I/httpsURLConnection﹕ </script>
01-14 16:14:23.292 2654-2669/it.js.ssocketio I/httpsURLConnection﹕ </body>
01-14 16:14:23.292 2654-2669/it.js.ssocketio I/httpsURLConnection﹕ </html>
...
01-14 16:14:24.063 2654-2683/it.js.ssocketio I/IO connect_error﹕ com.github.nkzawa.engineio.client.EngineIOException: xhr poll error
01-14 16:14:26.092 2654-2687/it.js.ssocketio I/IO connect_error﹕ com.github.nkzawa.engineio.client.EngineIOException: xhr poll error
...
$ sudo DEBUG=* node index.js
express:application compile etag weak +0ms
express:application compile query parser extended +46ms
express:application compile trust proxy false +9ms
express:application booting in development mode +7ms
express:router use / query +277ms
express:router:layer new / +5ms
express:router use / expressInit +11ms
express:router:layer new / +2ms
express:router use / serveStatic +5ms
express:router:layer new / +1ms
socket.io:server initializing namespace / +0ms
socket.io:server creating engine.io instance with opts {"path":"/socket.io"} +53ms
socket.io:server attaching client serving req handler +45ms
Listening on *:443
express:router dispatching GET / +22s
express:router query : / +29ms
express:router expressInit : / +9ms
express:router serveStatic : / +7ms
send stat "/home/pi/secure-webapp/public/index.html" +27ms
send pipe "/home/pi/secure-webapp/public/index.html" +20ms
send modified Wed, 14 Jan 2015 15:34:02 GMT +11ms
send etag W/"203-3867020799" +12ms
send content-type text/html +6ms
For Gingerbread and ICS
01-14 16:31:27.709 1795-1795/it.js.ssocketio I/https://raspberrypi/﹕ sslContext created
...
01-14 16:31:27.869 1795-1815/it.js.ssocketio I/IO connect_error﹕ com.github.nkzawa.engineio.client.EngineIOException: xhr poll error
...
01-14 16:31:27.909 1795-1809/it.js.ssocketio I/HostnameVerifier﹕ Approving certificate for raspberrypi
01-14 16:31:27.949 1795-1809/it.js.ssocketio I/httpsURLConnection﹕ url connected
...
01-14 16:31:28.179 1795-1809/it.js.ssocketio I/httpsURLConnection﹕ <!DOCTYPE html>
01-14 16:31:28.189 1795-1809/it.js.ssocketio I/httpsURLConnection﹕ <html>
01-14 16:31:28.189 1795-1809/it.js.ssocketio I/httpsURLConnection﹕ <head>
01-14 16:31:28.189 1795-1809/it.js.ssocketio I/httpsURLConnection﹕ <meta charset="UTF-8">
01-14 16:31:28.189 1795-1809/it.js.ssocketio I/httpsURLConnection﹕ <title>Title</title>
01-14 16:31:28.189 1795-1809/it.js.ssocketio I/httpsURLConnection﹕ <script src="/socket.io/socket.io.js"></script>
01-14 16:31:28.189 1795-1809/it.js.ssocketio I/httpsURLConnection﹕ </head>
01-14 16:31:28.189 1795-1809/it.js.ssocketio I/httpsURLConnection﹕ <body>
01-14 16:31:28.189 1795-1809/it.js.ssocketio I/httpsURLConnection﹕ <h1>Content of the document</h1>
01-14 16:31:28.189 1795-1809/it.js.ssocketio I/httpsURLConnection﹕ <script>
01-14 16:31:28.189 1795-1809/it.js.ssocketio I/httpsURLConnection﹕ var div = document.createElement('div');
01-14 16:31:28.189 1795-1809/it.js.ssocketio I/httpsURLConnection﹕ var socket = io.connect('https://raspberrypi/');
01-14 16:31:28.189 1795-1809/it.js.ssocketio I/httpsURLConnection﹕ socket.on('secure_data', function(secure_data) {
01-14 16:31:28.189 1795-1809/it.js.ssocketio I/httpsURLConnection﹕ console.log(secure_data);
01-14 16:31:28.189 1795-1809/it.js.ssocketio I/httpsURLConnection﹕ var p = document.createElement('p');
01-14 16:31:28.199 1795-1809/it.js.ssocketio I/httpsURLConnection﹕ p.appendChild(document.createTextNode('' + secure_data));
01-14 16:31:28.199 1795-1809/it.js.ssocketio I/httpsURLConnection﹕ document.body.appendChild(p);
01-14 16:31:28.199 1795-1809/it.js.ssocketio I/httpsURLConnection﹕ });
01-14 16:31:28.199 1795-1809/it.js.ssocketio I/httpsURLConnection﹕ </script>
01-14 16:31:28.199 1795-1809/it.js.ssocketio I/httpsURLConnection﹕ </body>
01-14 16:31:28.199 1795-1809/it.js.ssocketio I/httpsURLConnection﹕ </html>
...
01-14 16:31:28.949 1795-1825/it.js.ssocketio I/IO﹕ connect
01-14 16:31:30.009 1795-1828/it.js.ssocketio I/IO secure_data﹕ {"hello":"secure_world"}
01-14 16:31:30.939 1795-1831/it.js.ssocketio I/IO secure_data﹕ {"hello":"secure_world"}
...
$ sudo DEBUG=* node index.js
express:application compile etag weak +0ms
express:application compile query parser extended +46ms
express:application compile trust proxy false +9ms
express:application booting in development mode +7ms
express:router use / query +277ms
express:router:layer new / +5ms
express:router use / expressInit +11ms
express:router:layer new / +2ms
express:router use / serveStatic +5ms
express:router:layer new / +1ms
socket.io:server initializing namespace / +0ms
socket.io:server creating engine.io instance with opts {"path":"/socket.io"} +53ms
socket.io:server attaching client serving req handler +45ms
Listening on *:443
express:router dispatching GET / +45s
express:router query : / +30ms
express:router expressInit : / +9ms
express:router serveStatic : / +6ms
send stat "/home/pi/secure-webapp/public/index.html" +27ms
send pipe "/home/pi/secure-webapp/public/index.html" +73ms
send modified Wed, 14 Jan 2015 15:34:02 GMT +11ms
send etag W/"203-3867020799" +12ms
send content-type text/html +6ms
engine intercepting request for path "/socket.io/" +0ms
engine handling "GET" http request "/socket.io/?EIO=3&transport=polling" +14ms
engine handshaking client "P7_8gm23I5Ol-7UBAAAA" +60ms
engine:socket sending packet "open" ({"sid":"P7_8gm23I5Ol-7UBAAAA","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":60000}) +22ms
engine:polling setting request +19ms
engine:socket flushing buffer to transport +3ms
engine:polling writing " �0{"sid":"P7_8gm23I5Ol-7UBAAAA","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":60000}" +33ms
engine:socket executing batch send callback +21ms
socket.io:server incoming connection with id P7_8gm23I5Ol-7UBAAAA +45s
socket.io:client connecting to namespace / +0ms
socket.io:namespace adding socket to nsp / +0ms
socket.io:socket socket connected - writing packet +0ms
socket.io:socket joining room P7_8gm23I5Ol-7UBAAAA +3ms
socket.io:client writing packet {"type":0,"nsp":"/"} +48ms
socket.io-parser encoding packet {"type":0,"nsp":"/"} +0ms
socket.io-parser encoded {"type":0,"nsp":"/"} as 0 +4ms
engine:socket sending packet "message" (0) +77ms
socket.io:socket joined room P7_8gm23I5Ol-7UBAAAA +33ms
engine intercepting request for path "/socket.io/" +19ms
engine handling "GET" http request "/socket.io/?EIO=3&sid=P7_8gm23I5Ol-7UBAAAA&transport=polling" +2ms
engine setting new request for existing client +6ms
engine:polling setting request +2ms
engine:socket flushing buffer to transport +3ms
engine:polling writing "�40" +5ms
engine:socket executing batch send callback +9ms
engine intercepting request for path "/socket.io/" +30ms
engine handling "GET" http request "/socket.io/?EIO=3&sid=P7_8gm23I5Ol-7UBAAAA&transport=polling" +2ms
engine setting new request for existing client +4ms
engine:polling setting request +2ms
socket.io:client writing packet {"type":2,"data":["secure_data",{"hello":"secure_world"}],"nsp":"/"} +1s
socket.io-parser encoding packet {"type":2,"data":["secure_data",{"hello":"secure_world"}],"nsp":"/"} +1s
socket.io-parser encoded {"type":2,"data":["secure_data",{"hello":"secure_world"}],"nsp":"/"} as 2["secure_data",{"hello":"secure_world"}] +3ms
engine:socket sending packet "message" (2["secure_data",{"hello":"secure_world"}]) +950ms
engine:socket flushing buffer to transport +2ms
engine:polling writing "�42["secure_data",{"hello":"secure_world"}]" +3ms
engine intercepting request for path "/socket.io/" +25ms
engine handling "GET" http request "/socket.io/?EIO=3&sid=P7_8gm23I5Ol-7UBAAAA&transport=polling" +2ms
engine setting new request for existing client +3ms
engine:polling setting request +2ms
engine:socket executing batch send callback +2ms
socket.io:client writing packet {"type":2,"data":["secure_data",{"hello":"secure_world"}],"nsp":"/"} +1s
socket.io-parser encoding packet {"type":2,"data":["secure_data",{"hello":"secure_world"}],"nsp":"/"} +1s
socket.io-parser encoded {"type":2,"data":["secure_data",{"hello":"secure_world"}],"nsp":"/"} as 2["secure_data",{"hello":"secure_world"}] +2ms
engine:socket sending packet "message" (2["secure_data",{"hello":"secure_world"}]) +1s
engine:socket flushing buffer to transport +2ms
engine:polling writing "�42["secure_data",{"hello":"secure_world"}]" +3ms
engine intercepting request for path "/socket.io/" +99ms
engine handling "GET" http request "/socket.io/?EIO=3&sid=P7_8gm23I5Ol-7UBAAAA&transport=polling" +2ms
engine setting new request for existing client +3ms
engine:polling setting request +2ms
engine:socket executing batch send callback +2ms
socket.io:client writing packet {"type":2,"data":["secure_data",{"hello":"secure_world"}],"nsp":"/"} +1s
socket.io-parser encoding packet {"type":2,"data":["secure_data",{"hello":"secure_world"}],"nsp":"/"} +1s
socket.io-parser encoded {"type":2,"data":["secure_data",{"hello":"secure_world"}],"nsp":"/"} as 2["secure_data",{"hello":"secure_world"}] +2ms
engine:socket sending packet "message" (2["secure_data",{"hello":"secure_world"}]) +923ms
engine:socket flushing buffer to transport +1ms
engine:polling writing "�42["secure_data",{"hello":"secure_world"}]" +3ms
...
No clue if I missed something else!?
from socket.io-client-java.
Ok that was fast xD.
In the end it was something that I missed in the code.
The line after IO.setDefaultSSLContext()
you have to put
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
or provide your own implementation of the HostnameVerifier interface. Pay attention that this is the global setting via the static method HttpsURLConnection#setDefaultHostnameVerifier
. Maybe it should be mentioned in the readme?
from socket.io-client-java.
Hello,
On my side, everything is good until Android Lollipop : stumbled accross a "timeout" SocketIOException, and I can't figure out why.
Any ideas ?
from socket.io-client-java.
@hgshoggins Did you find any solutions for TimeOut issue on Lollipop devices? My code is working fine on pre lollipop devices but on lollipop it is giving me timeout issue.
from socket.io-client-java.
Hello @wingoku. No luck on my side, I had to use plain text on my ws, and make sure I was not transporting any sensitive data.
I first wanted to use it because in plain HTTP, some GSM BTS mangle the content sent by a Device : I got myself with some strange X-NOKIA-xxxx headers that I did not want to be added, that is why I preferred to use HTTPS.
from socket.io-client-java.
Can you try just released v0.5.0 which the websocket transport is replaced with OkHttp ?
from socket.io-client-java.
@j54n1n great man, your's is the best solution on the issue of https connection.
from socket.io-client-java.
I am using this with HTTPS and it requires no hacking or workaround. Using v0.5.1.
@anshulvij @nkzawa is it ok to close this?
from socket.io-client-java.
@shuoli84 ,
can you share your connection code? Perhaps that would help me figure out what I am doing wrong? Coz I am having the same issue as mentioned above by @j54n1n
com.github.nkzawa.engineio.client.EngineIOException: xhr poll error
I am using v0.5.2
from socket.io-client-java.
I was also having xhr poll error, what resolved the issue was:
@jonathanve code and also updating socket.io library from v0.3.0 to v0.6.2. I did not establish SSL security within node.js like @j54n1n suggested, instead I defined them in my nginx server configuration.
from socket.io-client-java.
@jonathanve Did you deleted https://github.com/jonathanve/socket-io-android?
from socket.io-client-java.
@wpq2014 yes, let me restore it then. Since no comments were posted since October 2015, I thought It was not longer needed.
from socket.io-client-java.
@marekyggdrasil could you please explain how you did it on Nginx? We have a similar situation and we haven't been able to figure out how to fix it. thanks
from socket.io-client-java.
Closed due to inactivity, please reopen if needed.
from socket.io-client-java.
hello!
I get this strange error:
E/Socket: Socket connection can not be established
my SocketHelper.java is:
private SocketHelper() {
try {
IO.Options options = new IO.Options();
options.forceNew = true;
socket = IO.socket(SOCKET_URL, options);
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
and error comes from VehicleBidFragmentPresenterImp.java is:
public void initSocketHelper(String userId, int auctionId) {
SocketHelper.getInstance().connect(new SocketHelper.SocketCallBack() {
@OverRide
public void onConnect(Object... args) {
// send first bid for wake up socket
sendBid(userId, 4, "1", String.valueOf(auctionId), Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTimeInMillis());
}
@Override
public void onDisConnect(Object... args) {
Log.d("Socket", "Socket connection close");
}
@Override
public void onError(Object... args) {
Log.e("Socket", "Socket connection can not be established");
}
@Override
public void onTimeOut(Object... args) {
if (getView() != null && getView().get() != null)
getView().get().bidError("Bağlantınız zaman aşımına uğradı lütfen tekrar bağlanmayı deneyiniz.");
}
@Override
public void onBidError(Object... args) {
if (args != null && args.length > 0) {
try {
for (Object data : args) {
if (data == null)
break;
AuctionBidErrorModel bidModel = parseSocketError(data.toString());
if (bidModel == null) {
getView().get().bidError("Bir hata oluştu daha sonra tekrar deneyiniz.");
return;
}
long id = bidModel.getAuctionId();
if (id == auctionId && userId.equals(bidModel.getKey())) {
Log.d("Socket", " Error --> " + data.toString());
getView().get().bidError(bidModel.getMessage());
}
}
} catch (Exception ignore) {
ignore.printStackTrace();
}
}
}
@Override
public void onBidPublish(Object... args) {
try {
if (getView() != null && getView().get() != null) {
for (Object data : args) {
if (data == null)
break;
AuctionBidModel bidModel = parseSocket(data.toString());
if (bidModel == null) {
getView().get().bidError("Bir hata oluştu daha sonra tekrar deneyiniz.");
return;
}
long id = bidModel.getAuctionId();
if (id == auctionId && bidModel.getSendType() != 4) {
Log.d("Socket", " BidPublish --> " + data.toString());
getView().get().bidSend(bidModel);
}
}
}
} catch (Exception ignore) {
ignore.printStackTrace();
}
}
@Override
public void onClose(Object... args) {
try {
if (args != null)
Log.d("SocketHelper", "" + Arrays.toString(args));
if (getView() != null && getView().get() != null && args != null) {
for (Object data : args) {
if (data == null)
break;
AuctionBidModel bidModel = parseSocket(data.toString());
if (bidModel == null) {
return;
}
long id = bidModel.getAuctionId();
if (id == auctionId && bidModel.getSendType() != 4) {
Log.d("Socket", " Close --> " + data.toString());
getView().get().auctionClose();
}
}
}
} catch (Exception ignore) {
ignore.printStackTrace();
}
}
@Override
public void autoSellCancel(Object... args) {
try {
if (args != null)
Log.d("SocketHelper", "" + Arrays.toString(args));
if (getView() != null && getView().get() != null && args != null) {
for (Object data : args) {
if (data == null)
break;
AuctionBidModel bidModel = parseSocket(data.toString());
if (bidModel == null) {
return;
}
long id = bidModel.getAuctionId();
if (id == auctionId && bidModel.getSendType() != 4) {
Log.d("Socket", " SellCancel --> " + data.toString());
getView().get().autoSellCancel();
}
}
}
} catch (Exception ignore) {
ignore.printStackTrace();
}
}
@Override
public void autoSell(Object... args) {
try {
if (args != null)
Log.d("SocketHelper", "" + Arrays.toString(args));
if (getView() != null && getView().get() != null && args != null) {
for (Object data : args) {
if (data == null)
break;
AuctionBidModel bidModel = parseSocket(data.toString());
if (bidModel == null) {
return;
}
long id = bidModel.getAuctionId();
if (id == auctionId && bidModel.getSendType() != 4) {
Log.d("Socket", " AutoSell --> " + data.toString());
getView().get().autoSell();
}
}
}
} catch (Exception ignore) {
ignore.printStackTrace();
}
}
@Override
public void auctionCounterUpdate(Object... args) {
try {
if (args != null)
Log.d("SocketHelper", "" + Arrays.toString(args));
if (getView() != null && getView().get() != null && args != null) {
for (Object data : args) {
if (data == null)
break;
AuctionBidModel bidModel = parseSocket(data.toString());
if (bidModel == null) {
return;
}
long id = bidModel.getAuctionId();
if (id == auctionId && bidModel.getSendType() != 4) {
Log.d("Socket", " CounterUpdate --> " + data.toString());
getView().get().auctionCounterUpdate(bidModel.getNewTotalSeconds());
}
}
}
} catch (Exception ignore) {
ignore.printStackTrace();
}
}
});
}
please help me to solve this problem.
from socket.io-client-java.
Related Issues (20)
- socket.io client sometimes sends arrays wrong HOT 5
- can i use multiple socket connection ?
- Android 13 not available HOT 1
- It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible HOT 3
- sendBuffer should be accessible
- Getting EVENT_CONNECT_ERROR from Android to Node HOT 1
- Change/update auth or query or extraheaders containing token after connection HOT 1
- Is this project Still Alive? HOT 3
- How to listen to Manager events? (Socket events are working) HOT 2
- Straightforward logging option for Android
- testDecodeError function in Helpers.java error message clean up HOT 2
- Report: ConcurrentModificationException when use AckWithTimout... HOT 2
- Connection state recovery HOT 1
- NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference HOT 1
- Unable to emit JSON object instead it is emitting Stringified Json in Client Version - 1.0.2 HOT 2
- Implement Connection State Recovery
- it throws java.lang.ClassCastException when sending nested json data. HOT 1
- in the this one the depencies are not dwonloading for me
- Android 14 not compatible with version 2.1.0
- received disconnect event. and socket closed.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from socket.io-client-java.