HI, I have the next error:
com.github.nkzawa.engineio.client.EngineIOException: xhr poll error
I'm not use maven and I added the jar libreries manually..
engine.io-client-0.3.0.jar
Java-WebSocket-1.3.0.jar
json-201440107.jar
socket.io-client-0.2.0.jar
This is my code on android:
try{
Options opts = new IO.Options();
opts.port = 80;
socket = IO.socket("http://192.168.0.2",opts);
socket.connect();
Log.i("Set Socket IO", "Socket IO Seting");
} catch (Exception e) {
Log.e("Socket Problem", "Try cath", e);
}
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override
public void call(Object... args) {
socket.emit("test", "hi");
Log.i("Make Emit","Emit");
socket.disconnect();
}
});
socket.on("event", new Emitter.Listener() {
@Override
public void call(Object... args) {
Log.i("Event","test event");
}
});
socket.on(Socket.EVENT_DISCONNECT, new Emitter.Listener() {
@Override
public void call(Object... args) {
Log.i("desc","error desc");
}
});
socket.on(Socket.EVENT_CONNECT_ERROR , new Emitter.Listener() {
@Override
public void call(Object... args) {
//JSONObject obj = (JSONObject)args[0];
Log.i("Error",args[0].toString());
}
});
socket.on(Socket.EVENT_ERROR , new Emitter.Listener() {
@Override
public void call(Object... args) {
Log.i("Error","Event Error");
}
});
socket.on(Socket.EVENT_RECONNECTING , new Emitter.Listener() {
@Override
public void call(Object... args) {
Log.i("Error","Event reconectiong Error");
}
});
This is my code of node.js:
var _io = require('socket.io')();
_io.listen(80);
_io.on('connection',function(socket){
socket.on('test',function(data,fn){
console.log(data);
});
});
And the logcat says this:
10-28 12:29:00.772: I/Error(27117): Event reconectiong Error
10-28 12:29:00.795: I/Error(27117): com.github.nkzawa.engineio.client.EngineIOException: xhr poll error
What can I do?
The url (192.168.0.2) looks private IP address. Is this correct?
Hi, I miss the uses permition for internet and wifi. Your library works perfectly and is awesome. :)
Thanks.
Hi,
I have set the permissions on my pom.
I am still getting the same error.
[com.github.nkzawa.engineio.client.EngineIOException: xhr poll error]
Would this be something else?
I am also getting the same error "com.github.nkzawa.engineio.client.EngineIOException: xhr poll error"
though I have set the Internet-permissions.
How can I resolve this?
Try to access to that IP from your phone, (ping YOUR_LOCAL_IP). from your mobile. If you can't that is the problem.
I build with this library my own Adaptor here: https://github.com/cmarrero01/socket.io-client.java I'm pretty sure that this library works perfectly, so I think is a comunication issue with your devices.
Solved it by :
IO.setDefaultHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
//TODO: Make this more restrictive
return true;
}
});
You can make a PR if you want.
is anybody solve this issue
I have the same error but do not resolve it at all.
same issue, I have no idea what going wrong
same issue, I have no idea what going wrong
this may be the server cause. delete the pingInterval and pingTimeout.
var io = require('socket.io').listen(server, {
// pingInterval: 120000,
// pingTimeout: 60000,
logger: logger
});
have try~
val opts = IO.Options()
opts.transports = arrayOf(WebSocket.NAME)
I also have this error, but on old Android devices and emulators (API 19, 21). If set opts.transports = arrayOf(WebSocket.NAME), it will lead to another error: io.socket.engineio.client.EngineIOException: websocket error.
Thanks to https://github.com/socketio/socket.io-client-java/issues/281#issuecomment-487091561 and https://stackoverflow.com/a/63395069/2914140 I wrote:
okHttpClient = getOkHttpBuilder()
.connectTimeout(60, TimeUnit.SECONDS)
.readTimeout(60, TimeUnit.SECONDS)
.writeTimeout(60, TimeUnit.SECONDS)
// or other options.
.build()
private fun getUnsafeOkHttpClient(): OkHttpClient.Builder =
try {
// Create a trust manager that does not validate certificate chains
val trustAllCerts: Array<TrustManager> = arrayOf(
object : X509TrustManager {
@Throws(CertificateException::class)
override fun checkClientTrusted(chain: Array<X509Certificate?>?,
authType: String?) = Unit
@Throws(CertificateException::class)
override fun checkServerTrusted(chain: Array<X509Certificate?>?,
authType: String?) = Unit
override fun getAcceptedIssuers(): Array<X509Certificate> = arrayOf()
}
)
// Install the all-trusting trust manager
val sslContext: SSLContext = SSLContext.getInstance("SSL")
sslContext.init(null, trustAllCerts, SecureRandom())
// Create an ssl socket factory with our all-trusting manager
val sslSocketFactory: SSLSocketFactory = sslContext.socketFactory
val builder = OkHttpClient.Builder()
builder.sslSocketFactory(sslSocketFactory,
trustAllCerts[0] as X509TrustManager)
builder.hostnameVerifier { _, _ -> true }
builder
} catch (e: Exception) {
throw RuntimeException(e)
}
private fun getOkHttpBuilder(): OkHttpClient.Builder =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
OkHttpClient().newBuilder()
} else {
getUnsafeOkHttpClient()
}
Then set socket (in another class):
private fun getOptions(): IO.Options {
IO.setDefaultOkHttpWebSocketFactory(okHttpClient)
IO.setDefaultOkHttpCallFactory(okHttpClient)
return IO.Options().apply {
forceNew = true
reconnectionAttempts = Integer.MAX_VALUE;
reconnection = true
secure = true
timeout = 1000
transports = arrayOf(Polling.NAME, PollingXHR.NAME, WebSocket.NAME)
query = "..."
}
}
val options = getOptions()
socket = try {
IO.socket(SOCKET_URL, options)
...
Java Code resolve this error
try {
IO.Options options = new IO.Options();
options.transports = new String[]{WebSocket.NAME};
mSocket = IO.socket("http://XXX.XXX.XX.XX:9998/", options);
mSocket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override
public void call(Object... args) {
Log.i(TAG, Socket.EVENT_CONNECT);
}
}).on(Socket.EVENT_DISCONNECT, new Emitter.Listener() {
@Override
public void call(Object... args) {
Log.i(TAG, Socket.EVENT_DISCONNECT);
}
}).on(Socket.EVENT_CONNECT_ERROR, new Emitter.Listener() {
@Override
public void call(Object... args) {
String err = args[0].toString();
Log.i(TAG, "eroor " + err);
}
});
mSocket.on("userjoinedthechat", new Emitter.Listener() {
@Override
public void call(Object... args) {
String data = (String) args[0];
Log.i(TAG, data);
}
});
mSocket.connect();
} catch (URISyntaxException e) {
e.printStackTrace();
}
Most helpful comment
have try~