socketio / engine.io-client-java Goto Github PK
View Code? Open in Web Editor NEWEngine.IO Client Library for Java
Home Page: http://socketio.github.io/engine.io-client-java
License: Other
Engine.IO Client Library for Java
Home Page: http://socketio.github.io/engine.io-client-java
License: Other
Its been in the code for roughly 20 days but we are still waiting on an actual release.
This has become absolutely necessary as clients who include socketio as well as the most recent version of okttp3 will see crashes.
We found that okhttp websocket client implementation is not stable when sending with 1M messages. (refer to this issue - square/okhttp#3317)
Other Java implementation seem to be more stable. Like Tyrus, NV-Websocket-Client).
So it would be better if you could provide a way to switch the Java client implementation.
I tried to update your library in my project form 0.7.0 to 0.8.0. But it gives me error, that it couldn't find it.
compile ('io.socket:socket.io-client:0.8.0') {
exclude group: 'org.json', module: 'json'
}
I'm on a project with version 0.5.2 and would like to upgrade to 0.7.0. Some API changes are reflected in the readme but there are others which can't be inferred from the javadocs. Is there a guide somewhere? One problematic API example would be the Socket.connected() method which doesn't exist in 0.7.0 any more.
Hi, I have an android app which was connected to socket io server(node.js).
Recently I have switched server to netty-socketio and updated to socket.io-client-java last version, and I noticed all clients running through proxy can´t connect.
Tried with 0.4.2 and works fine, but not with 0.5.0 and next versions. Seems to be a problem with okhttp-ws, but I didn´t find any errors on engine-io-client-java impl. Could be a problem related to okhttp-ws too, but I think it´s less probable -althrough I didn´t review okhttp-ws code-.
Is this an issue or I forbid something? If it is, how I could help to fix it?
Hi,
Whenever any special character comes in chat. Library[engine.io-client-0.2.1] crashed itself in ThreadPoolExector which causes application crashing.
Please give me any solution for now.
e.g. Receiving word "Väkiparta"
I have an Issue in received uni casting , because you gave us a general group chat group but i want private chat please tell me how this possible.
Hey,
Since I updated to socket.io-client-java 0.6.1
which uses engine.io-client-java 0.6.1
I keep getting
'websocket error' -- SocketTimeoutException
every few (10-15) seconds after a successful connection.
W/System.err﹕ java.net.SocketTimeoutException
09-08 23:39:36.427 14770-17678/com.myapp.staging W/System.err﹕ at java.net.PlainSocketImpl.read(PlainSocketImpl.java:488)
09-08 23:39:36.427 14770-17678/com.myapp.staging W/System.err﹕ at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:37)
09-08 23:39:36.427 14770-17678/com.myapp.staging W/System.err﹕ at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:237)
09-08 23:39:36.427 14770-17678/com.myapp.staging W/System.err﹕ at okio.Okio$2.read(Okio.java:139)
09-08 23:39:36.427 14770-17678/com.myapp.staging W/System.err﹕ at okio.AsyncTimeout$2.read(AsyncTimeout.java:211)
09-08 23:39:36.427 14770-17678/com.myapp.staging W/System.err﹕ at okio.RealBufferedSource.request(RealBufferedSource.java:71)
09-08 23:39:36.427 14770-17678/com.myapp.staging W/System.err﹕ at okio.RealBufferedSource.require(RealBufferedSource.java:64)
09-08 23:39:36.427 14770-17678/com.myapp.staging W/System.err﹕ at okio.RealBufferedSource.readByte(RealBufferedSource.java:77)
09-08 23:39:36.427 14770-17678/com.myapp.staging W/System.err﹕ at com.squareup.okhttp.internal.ws.WebSocketReader.readHeader(WebSocketReader.java:108)
09-08 23:39:36.427 14770-17678/com.myapp.staging W/System.err﹕ at com.squareup.okhttp.internal.ws.WebSocketReader.processNextFrame(WebSocketReader.java:97)
09-08 23:39:36.427 14770-17678/com.myapp.staging W/System.err﹕ at com.squareup.okhttp.internal.ws.RealWebSocket.readMessage(RealWebSocket.java:95)
09-08 23:39:36.427 14770-17678/com.myapp.staging W/System.err﹕ at com.squareup.okhttp.ws.WebSocketCall.createWebSocket(WebSocketCall.java:171)
09-08 23:39:36.434 14770-17678/com.myapp.staging W/System.err﹕ at com.squareup.okhttp.ws.WebSocketCall.access$000(WebSocketCall.java:42)
09-08 23:39:36.434 14770-17678/com.myapp.staging W/System.err﹕ at com.squareup.okhttp.ws.WebSocketCall$1.onResponse(WebSocketCall.java:102)
09-08 23:39:36.434 14770-17678/com.myapp.staging W/System.err﹕ at com.squareup.okhttp.Call$AsyncCall.execute(Call.java:168)
09-08 23:39:36.434 14770-17678/com.myapp.staging W/System.err﹕ at com.squareup.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33)
09-08 23:39:36.434 14770-17678/com.myapp.staging W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
09-08 23:39:36.434 14770-17678/com.myapp.staging W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
09-08 23:39:36.434 14770-17678/com.myapp.staging W/System.err﹕ at java.lang.Thread.run(Thread.java:818)
Than reconnecting also successful but after few seconds error again.
I'm in a loop of connections and disonnections..
Here is my server settings:
// Start the server
var app = express();
var server = app.listen(port);
var io = require('socket.io')(server, {
'log level': 2,
'polling duration': 10,
'close timeout': 12,
'heartbeat timeout': 30,
'heartbeat interval': 5,
'cookie': false
});
I'm having like a singelton socket in my Android App, here is function that creates it:
private Socket createSocket() {
IO.Options opts = new IO.Options();
opts.timeout = 10000;
opts.forceNew = true;
opts.reconnection = true;
opts.multiplex = true;
opts.reconnectionAttempts = Integer.MAX_VALUE;
try {
mSocket = IO.socket(mServerUrl, opts);
registerEvents();
} catch (URISyntaxException e) {
e.printStackTrace();
}
isConnected = false;
return mSocket;
}
Any ideas?
Same issue here > socketio/socket.io-client-java#295
This bug is the result of how you use the OkHttpClient object. In version 3 of OkHttp, do not recreate the instance OkHttpClient each use in your code:
I was using io.socket:socket.o-client:0.6.1 which works on Desktop & Android but not iOS because of this issue:
Now I've tried download SocketIO but it is mostly made up of
https://github.com/socketio/socket.io-client-java
but when trying this library it completely fails on all devices. (Doesn't respond to anything or throw any errors).
My main issue/confusion is
What's the main different between
https://github.com/socketio/socket.io-client-java (Working on everything except iOS = java.lang.IllegalArgumentException: unexpected url)
&
https://github.com/socketio/engine.io-client-java (Works on nothing but supplies socket.o-client-java)
I can't seem to get either of them working fully.
My main issue is what is https://github.com/socketio/socket.io-client-java doing that makes it work on everything but iOS that this library is doing so it works on nothing?
For our project we wanted to upgrade socket.io-client.java from 0.4.* to 0.5.2. On doing that the artifactory had trouble downloading the pom file of engine.io-client.java. The repo1.maven.org from which the files are downloaded has setting to generate Checksum if missing. Apparently the checksum generated by Artifactory does not match the checksum related to engine.io-client pom for version 0.5.1.
{
"errors" : [ {
"status" : 409,
"message" : "Rejected artifact download request: Checksum policy 'GEN_IF_ABSENT' rejected the artifact 'repo1-cache:com/github/nkzawa/engine.io-client/0.5.1/engine.io-client-0.5.1.pom'. rest of the message is hidden since it reveals checksum details.
}
Question:
I have created a simple Java app.
I'm connecting to a socket using the following URL pattern
String url = "http://host:port/channel";
socket = new Socket(url);
But I am getting the Xhr poll error, and I have not found any help because none of the examples use a url that specifies something after the port.
io.socket.engineio.client.EngineIOException: xhr poll error
Please help, I can provide code if needed.
When setting a custom path via the options, the request always contains an extra trailing / in the path.
IO.Options options = new IO.Options();
options.path = "/bin/engine.io";
Socket socket = IO.socket(uri, options);
will lead to the following request
http://myserver/bin/engine.io/?=&EIO=3&transport=polling
which is not supported on my server.
This code explicitly adds the trailing /:
Is there any specific reason for that ? Can we consider this as a bug ? I can do a PR, change is easy but impact might be huge.
Looks like a invalid delay value passed to reconnect. I'm running this on latest version
compile 'com.github.nkzawa:socket.io-client:0.4.1'
03-30 20:46:40.113: E/AndroidRuntime(10931): FATAL EXCEPTION: EventThread
03-30 20:46:40.113: E/AndroidRuntime(10931): Process: agilie.fandine.employee, PID: 10931
03-30 20:46:40.113: E/AndroidRuntime(10931): java.lang.IllegalArgumentException: delay < 0: -432345566375051264
03-30 20:46:40.113: E/AndroidRuntime(10931): at java.util.Timer.schedule(Timer.java:457)
03-30 20:46:40.113: E/AndroidRuntime(10931): at com.github.nkzawa.socketio.client.Manager.reconnect(Manager.java:497)
03-30 20:46:40.113: E/AndroidRuntime(10931): at com.github.nkzawa.socketio.client.Manager.access$2000(Manager.java:20)
03-30 20:46:40.113: E/AndroidRuntime(10931): at com.github.nkzawa.socketio.client.Manager$8$1$1.call(Manager.java:519)
03-30 20:46:40.113: E/AndroidRuntime(10931): at com.github.nkzawa.socketio.client.Manager$1$3.call(Manager.java:282)
03-30 20:46:40.113: E/AndroidRuntime(10931): at com.github.nkzawa.emitter.Emitter.emit(Emitter.java:117)
03-30 20:46:40.113: E/AndroidRuntime(10931): at com.github.nkzawa.engineio.client.Socket.onError(Socket.java:754)
03-30 20:46:40.113: E/AndroidRuntime(10931): at com.github.nkzawa.engineio.client.Socket.access$800(Socket.java:29)
03-30 20:46:40.113: E/AndroidRuntime(10931): at com.github.nkzawa.engineio.client.Socket$4.call(Socket.java:293)
03-30 20:46:40.113: E/AndroidRuntime(10931): at com.github.nkzawa.emitter.Emitter.emit(Emitter.java:117)
03-30 20:46:40.113: E/AndroidRuntime(10931): at com.github.nkzawa.engineio.client.Transport.onError(Transport.java:63)
03-30 20:46:40.113: E/AndroidRuntime(10931): at com.github.nkzawa.engineio.client.transports.PollingXHR.access$100(PollingXHR.java:19)
03-30 20:46:40.113: E/AndroidRuntime(10931): at com.github.nkzawa.engineio.client.transports.PollingXHR$6$1.run(PollingXHR.java:126)
03-30 20:46:40.113: E/AndroidRuntime(10931): at com.github.nkzawa.thread.EventThread$2.run(EventThread.java:75)
03-30 20:46:40.113: E/AndroidRuntime(10931): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
03-30 20:46:40.113: E/AndroidRuntime(10931): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
03-30 20:46:40.113: E/AndroidRuntime(10931): at java.lang.Thread.run(Thread.java:841)
Hi,
I am getting the following error while trying the example.
What am I missing?
var app = require('express')()
, server = require('http').createServer(app)
, io = require('socket.io').listen(server);
server.listen(3000);
io.sockets.on('connection', function (socket) {
socket.on("my other event", function(data){
console.log("my other event was called!!!")
console.log(data);
io.sockets.emit("my other event", data);
});
socket.on("message", function(data){
console.log("message event was called!!!")
console.log(data);
});
});
com.github.nkzawa.engineio.client.EngineIOException: xhr poll error
at com.github.nkzawa.engineio.client.Transport.onError(Transport.java:54)
at com.github.nkzawa.engineio.client.transports.PollingXHR.access$100(PollingXHR.java:16)
at com.github.nkzawa.engineio.client.transports.PollingXHR$6$1.run(PollingXHR.java:116)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Caused by: java.io.IOException: 404
at com.github.nkzawa.engineio.client.transports.PollingXHR$Request$1.run(PollingXHR.java:203)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
... 3 more
im working on socketio and engineio libraries, the souce of socketio is working with engineio version 0.8.3. the binary gradle version of engineio is working fine while the source code on github is different a bit.
package io.socket.engineio.client;
class Transport
binary versio has:
public static class Options {
public String hostname;
public String path;
public String timestampParam;
public boolean secure;
public boolean timestampRequests;
public int port = -1;
public int policyPort = -1;
public Map<String, String> query;
public SSLContext sslContext;
public HostnameVerifier hostnameVerifier;
protected Socket socket;
public Proxy proxy;
public String proxyLogin;
public String proxyPassword;
}
source code on github:
public static class Options {
public String hostname;
public String path;
public String timestampParam;
public boolean secure;
public boolean timestampRequests;
public int port = -1;
public int policyPort = -1;
public Map<String, String> query;
protected Socket socket;
public WebSocket.Factory webSocketFactory;
public Call.Factory callFactory;
}
Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String okhttp3.MediaType.toString()' on a null object reference
at io.socket.engineio.client.transports.PollingXHR$Request.onLoad(PollingXHR.java:271)
at io.socket.engineio.client.transports.PollingXHR$Request.access$700(PollingXHR.java:148)
at io.socket.engineio.client.transports.PollingXHR$Request$1.onResponse(PollingXHR.java:232)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:141)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Device: HTC One E9 dual sim
OS: 5.0.2
Could we please have a socket.isOpen() or socket.isOpening() to programmatically check the health of the socket? Thanks!
Issue:
I have been having issue with 100's of Out of Memory exceptions in my Android app which is using socket.io-client-java library since couple of months and I've been trying a lot to figure out. The library uses engine.io library.
Hypothesis:
After doing some exploration, this is the hypothesis I have. Please feel free to suggest your thoughts or a fix. In Websocket.java file, each time doOpen()
is being called, a new instance of OkHttpClient
is being initialized as follows:
public void doOpen() {
// .....
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder()
// turn off timeouts (github.com/socketio/engine.io-client-java/issues/32)
.connectTimeout(0, TimeUnit.MILLISECONDS)
.readTimeout(0, TimeUnit.MILLISECONDS)
.writeTimeout(0, TimeUnit.MILLISECONDS);
// ...
final OkHttpClient client = clientBuilder.build();
// ...
}
Based on a comment by swankjesse at Square, on an issue opened on okhttp regarding the OOM exceptions, he suggested to share the instance of OkHttpClient
. Otherwise each time when we are creating a new instance of OkHttpClient
, it will hold its own connection pool and thread pool, which is what seems to be happening when calling doOpen()
in Websocket.java
. An app which closes connection and opens connection multiple times in its workflow is having lot of OOM exceptions (stacktrace same as on square/okhttp#2846). When a mobile app goes in background, one would want to close connection to prevent using resources and then re-open connection when app is visible.
From the okhttp docs:
OkHttp performs best when you create a single OkHttpClient instance and reuse it for all of your HTTP calls. This is because each client holds its own connection pool and thread pools. Reusing connections and threads reduces latency and saves memory. Conversely, creating a client for each request wastes resources on idle pools.
Solution seems to be fixing it as mentioned in the docs. Feel free to comment if the hypothesis seems wrong.
Thanks
References:
on version 0.8.1
Fatal Exception: java.lang.IndexOutOfBoundsException: index=5, limit=5 at java.nio.Buffer.checkIndex(Buffer.java:156) at java.nio.HeapByteBuffer.get(HeapByteBuffer.java:115) at io.socket.engineio.parser.Parser.decodePayload(Parser.java:211) at io.socket.engineio.client.transports.Polling._onData(Polling.java:134) at io.socket.engineio.client.transports.Polling.onData(Polling.java:106) at io.socket.engineio.client.transports.PollingXHR$5$1.run(PollingXHR.java:111) at io.socket.thread.EventThread$2.run(EventThread.java:80) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) at java.lang.Thread.run(Thread.java:856)
04-02 11:57:01.306 20233-6243/A/art: art/runtime/indirect_reference_table.cc:115] JNI ERROR (app bug): weak global reference table overflow (max=51200)
04-02 11:57:01.308 20233-6243/A/art: art/runtime/indirect_reference_table.cc:115] weak global reference table dump:
04-02 11:57:01.308 20233-6243/A/art: art/runtime/indirect_reference_table.cc:115] Last 10 entries (of 51200):
04-02 11:57:01.308 20233-6243/A/art: art/runtime/indirect_reference_table.cc:115] 51199: 0x12e76d00 io.socket.thread.EventThread
04-02 11:57:01.308 20233-6243/A/art: art/runtime/indirect_reference_table.cc:115] 51198: 0x12e76ca0 io.socket.thread.EventThread
04-02 11:57:01.308 20233-6243/A/art: art/runtime/indirect_reference_table.cc:115] 51197: 0x12e8c940 io.socket.thread.EventThread
04-02 11:57:01.308 20233-6243/A/art: art/runtime/indirect_reference_table.cc:115] 51196: 0x12e76c40 io.socket.thread.EventThread
04-02 11:57:01.308 20233-6243/A/art: art/runtime/indirect_reference_table.cc:115] 51195: 0x12e7eee0 io.socket.thread.EventThread
04-02 11:57:01.308 20233-6243/A/art: art/runtime/indirect_reference_table.cc:115] 51194: 0x12e76be0 io.socket.thread.EventThread
04-02 11:57:01.308 20233-6243/A/art: art/runtime/indirect_reference_table.cc:115] 51193: 0x12e7ed60 io.socket.thread.EventThread
04-02 11:57:01.308 20233-6243/A/art: art/runtime/indirect_reference_table.cc:115] 51192: 0x12e76b80 io.socket.thread.EventThread
04-02 11:57:01.308 20233-6243/A/art: art/runtime/indirect_reference_table.cc:115] 51191: 0x12e7ebe0 io.socket.thread.EventThread
04-02 11:57:01.309 20233-6243/A/art: art/runtime/indirect_reference_table.cc:115] 93 of io.socket.thread.EventThread (93 unique instances)
Hi!
I have a problem with app termination. The trace of hang thread is:
pool-4-thread-1@1497, prio=5, in group 'main', status: 'RUNNING'
at java.net.SocketInputStream.socketRead0(SocketInputStream.java:-1)
at java.net.SocketInputStream.read(SocketInputStream.java:150)
at java.net.SocketInputStream.read(SocketInputStream.java:121)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:275)
at java.io.BufferedInputStream.read(BufferedInputStream.java:334)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:633)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:579)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1322)
at sun.net.www.protocol.http.HttpURLConnection.getHeaderFields(HttpURLConnection.java:2700)
at com.github.nkzawa.engineio.client.transports.PollingXHR$Request$1.run(PollingXHR.java:204)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Context: square/okhttp#1652
Specific lines that touch each other:
This part creates a URL with the ws/wss:// scheme:
https://github.com/nkzawa/engine.io-client.java/blob/master/src/main/java/com/github/nkzawa/engineio/client/transports/WebSocket.java#L194
This disallows that:
https://github.com/square/okhttp/blob/master/okhttp/src/main/java/com/squareup/okhttp/HttpUrl.java#L880
I believe Square will eventually make changes to fix this. However, in the meantime, stick to OkHttp 2.3.0 to avoid this problem.
Hello,
I am indirectly a user of engine.io-client-java via socket.io-client-java. I have a server that for reasons which I hope to rectify later fails to correctly respond to the requests the polling transport makes. When the socket.io-client-java library is setup to only use websockets it is able to connect to the server just fine. If I leave the default set of transport in place (polling and websockets) the client fails to successfully connect.
What appears to happen (from the logs) is engine.io-client-java starts both the websocket and the polling transport, and when the polling transport fails, it kills the socket and makes the whole thing as a failure without checking the websocket connection.
It seems like it would be better to be able to continue to use the websocket connection.
Thanks
hi , I am a new bee to android.
If you have fixed the above mentioned commit then please release it to use in graddle.
i have to use it.
Thanks in advance,
I recently found this repository and so I added the compile statement to my build.gradle and it creates these warnings on debug:
WARNING: Dependency org.json:json:20090211 is ignored for debug as it may be conflicting with the internal version provided by Android.
In case of problem, please repackage with jarjar to change the class packages
WARNING: Dependency org.json:json:20090211 is ignored for release as it may be conflicting with the internal version provided by Android.
In case of problem, please repackage with jarjar to change the class packages
I'm running android 4.4.4 on my device.
The Polling XHR class is disconnecting from the HttpURLConnection before closing the streams (or the reader), This causes the TCP connection to be closed without the possibility of being cached by the JVM.
Also, it just does not seem correct to first call disconnect and then closing the InputStream of the connection.
This probably is not a problem for most people as I guess most use websockets instead of polling
what different ?
i want to develop android realtime push service?
My javascript client works for URL like
IO.socket("http://localhost:3030?token="+ api_token, option);
I need your Java client to do performance testing.
But it seems to me that my server side cannot get the api_token from the above URL.
OKHttp websocket fixed several issues. Do you mind release one version to maven? Thanks for the hard work.
I see that c8bdd27 made changes to work with OkHttp 2.7.0, however the released POM still pulls in 2.5.0 as it hasn't yet been updated.
OkHttp-WS 2.5.0 is incompatible with OkHttp 2.7.0, meaning that apps which use your project - even as a transitive dependency - cannot upgrade to OkHttp 2.7.0 until SocketIO releases a fix.
A load test yielded the following exception (see also #54) from time to time:
2016-04-26 13:12:18,080 [EventThread] ERROR EventThread:81 - Task threw exception
java.lang.IllegalStateException: must call close()
at okhttp3.internal.ws.RealWebSocket.sendMessage(RealWebSocket.java:108) ~[na:na]
at io.socket.engineio.client.transports.WebSocket$3.call(WebSocket.java:173) ~[na:na]
at io.socket.engineio.parser.Parser.encodePacket(Parser.java:63) ~[na:na]
at io.socket.engineio.parser.Parser.encodePacket(Parser.java:42) ~[na:na]
at io.socket.engineio.client.transports.WebSocket.write(WebSocket.java:168) ~[na:na]
at io.socket.engineio.client.Transport$3.run(Transport.java:101) ~[na:na]
at io.socket.thread.EventThread.exec(EventThread.java:54) ~[na:na]
at io.socket.engineio.client.Transport.send(Transport.java:96) ~[na:na]
at io.socket.engineio.client.Socket.flush(Socket.java:605) ~[na:na]
at io.socket.engineio.client.Socket.onDrain(Socket.java:596) ~[na:na]
at io.socket.engineio.client.Socket.access$1100(Socket.java:30) ~[na:na]
at io.socket.engineio.client.Socket$6.call(Socket.java:298) ~[na:na]
at io.socket.emitter.Emitter.emit(Emitter.java:117) ~[na:na]
at io.socket.engineio.client.transports.WebSocket$2$1.run(WebSocket.java:160) ~[na:na]
at io.socket.thread.EventThread$2.run(EventThread.java:79) ~[na:na]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_06]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_06]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_06]
The reason is probably that IOExceptions thrown from okhttp3's RealWebSocket.sendMessage do not lead to the engine.io WebSocket being properly closed.
By the way: consider logging in WebSocket L.178 as 'warning' at least, and add the original IOException.
Disconnect in a few seconds after I connect the service!
Why? What need me setting?
And I found it disconnect in 10 seconds.
im working on socketio and engineio libraries, the souce of socketio is working with engineio version 0.8.3. the binary gradle version of engineio is working fine while the source code on github is different a bit.
package io.socket.engineio.client;
class Transport
binary versio has:
public static class Options {
public String hostname;
public String path;
public String timestampParam;
public boolean secure;
public boolean timestampRequests;
public int port = -1;
public int policyPort = -1;
public Map<String, String> query;
public SSLContext sslContext;
public HostnameVerifier hostnameVerifier;
protected Socket socket;
public Proxy proxy;
public String proxyLogin;
public String proxyPassword;
}
source code on github:
public static class Options {
public String hostname;
public String path;
public String timestampParam;
public boolean secure;
public boolean timestampRequests;
public int port = -1;
public int policyPort = -1;
public Map<String, String> query;
protected Socket socket;
public WebSocket.Factory webSocketFactory;
public Call.Factory callFactory;
}
Hi
Thanks for the great library! We have an Android app using socket io and we're seeing a lot of crashes due to following exception:
Fatal Exception: java.lang.IllegalStateException: Unable to take ownership of connection.
at com.squareup.okhttp.ws.WebSocketCall.createWebSocket(WebSocketCall.java:157)
at com.squareup.okhttp.ws.WebSocketCall.access$000(WebSocketCall.java:42)
at com.squareup.okhttp.ws.WebSocketCall$1.onResponse(WebSocketCall.java:102)
at com.squareup.okhttp.Call$AsyncCall.execute(Call.java:168)
at com.squareup.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
This is coming from okhttp
library being used in socketio
. After I see lots of failed attempts to connect as shown in following logs, the above crash happens:
**11:35:45:579** : error: io.socket.engineio.client.EngineIOException: websocket error
Socket.EVENT_DISCONNECT: onDisconnectListener called: Socket disconnected.
.... // Lot of same exceptions as below
Socket.EVENT_DISCONNECT: onDisconnectListener called: Socket disconnected.
Socket.EVENT_CONNECT: Socket connection established...
io.socket.engineio.client.EngineIOException: xhr post error
Socket.EVENT_DISCONNECT: onDisconnectListener called: Socket disconnected.
Socket.EVENT_CONNECT: Socket connection established...
error: io.socket.engineio.client.EngineIOException: xhr poll error
Socket.EVENT_DISCONNECT: onDisconnectListener called: Socket disconnected.
io.socket.engineio.client.EngineIOException: xhr poll error
Socket.EVENT_DISCONNECT: onDisconnectListener called: Socket disconnected.
**11:47:46:355** io.socket.engineio.client.EngineIOException: xhr poll error
...
Not sure of the error type event. We use the same error callback for EVENT_ERROR
, EVENT_CONNECT_ERROR
, EVENT_CONNECT_TIMEOUT
, EVENT_RECONNECT_ERROR
, EVENT_RECONNECT_FAILED
. Although from the timestamps it seems like a timeout.
The version of library being used is: io.socket:socket.io-client:0.6.2
.
Someone opened an Issue with okhttp regarding this exception but not sure if it is an error on their side. Please let me know if you need more details.
Hello,
The server can return specific error code on allowRequest: as follows,
'allowRequest': function(handshake, fn) { fn(666, false); return; ..... )....
But, the Client code at this does not read the error code (body). As a result, mSocket.on(Socket.EVENT_CONNECT_ERROR, onConnectError); has no way to capture the error code.
the patch we did,
using ,
self.onError(new IOException(response.body().string()));
insted of,
self.onError(new IOException(Integer.toString(response.code())));
-Thanks
trying to add cookie to headers
I/SOCKET﹕ ERROR io.socket.engineio.client.EngineIOException: xhr poll error
compile 'io.socket:socket.io-client:0.6.1'
compile 'io.socket:engine.io-client:0.6.1'
server nodejs socket.io 1.3.5
opts = new Socket.Options();
opts.host = "http://192.168.0.12";
opts.port = 3030;
socket = new Socket(opts);
// socket.setDefaultHostnameVerifier(new HostnameVerifier() {
// @Override
// public boolean verify(String hostname, SSLSession session) {
// return true;
// }
// });
socket.on(Socket.EVENT_TRANSPORT, new Emitter.Listener() {
@Override
public void call(Object... args) {
Transport transport = (Transport)args[0];
transport.on(Transport.EVENT_REQUEST_HEADERS, new Emitter.Listener() {
@Override
public void call(Object... args) {
@SuppressWarnings("unchecked")
Map<String, List<String>> headers = (Map<String, List<String>>) args[0];
headers.put("Cookie", Arrays.asList(authCookie));
//Log.i("SOCKET", String.valueOf(headers.size()));
}
});
}
});
socket.on(Socket.EVENT_ERROR, new Emitter.Listener() {
@Override
public void call(Object... args) {
Log.i("SOCKET", "ERROR " + String.valueOf(args[0]));
}
});
socket.open();
I am using latest socket.io-client.java library in my android client. It internally uses engine.io-client.java 0.5.1 version. This library is giving NPE while sending a packet. Following is the stack trace. Please fix it soon. According to the stack trace, error is thrown in the following line.
self.ws.sendMessage(TEXT, new Buffer().writeUtf8((String) packet));
Can self.ws object be null in any scenario ?
java.lang.NullPointerException:
at com.github.nkzawa.engineio.client.transports.WebSocket$2.void call(java.lang.Object)()(SourceFile:148)
at com.github.nkzawa.engineio.parser.Parser.void encodePacket(com.github.nkzawa.engineio.parser.Packet,boolean,com.github.nkzawa.engineio.parser.Parser$EncodeCallback)()(SourceFile:63)
at com.github.nkzawa.engineio.parser.Parser.void encodePacket(com.github.nkzawa.engineio.parser.Packet,com.github.nkzawa.engineio.parser.Parser$EncodeCallback)()(SourceFile:42)
at com.github.nkzawa.engineio.client.transports.WebSocket.void write(com.github.nkzawa.engineio.parser.Packet[])()(SourceFile:143)
at com.github.nkzawa.engineio.client.Transport$3.void run()()(SourceFile:101)
at com.github.nkzawa.thread.EventThread.void exec(java.lang.Runnable)()(SourceFile:50)
at com.github.nkzawa.engineio.client.Transport.void send(com.github.nkzawa.engineio.parser.Packet[])()(SourceFile:97)
at com.github.nkzawa.engineio.client.Socket.void flush()()(SourceFile:611)
at com.github.nkzawa.engineio.client.Socket.void onDrain()()(SourceFile:602)
at com.github.nkzawa.engineio.client.Socket.void access$1000(com.github.nkzawa.engineio.client.Socket)()(SourceFile:30)
void access$1600(com.github.nkzawa.engineio.client.Socket,java.lang.String)
at com.github.nkzawa.engineio.client.Socket$6.void call(java.lang.Object[])()(SourceFile:295)
at com.github.nkzawa.emitter.Emitter.com.github.nkzawa.emitter.Emitter emit(java.lang.String,java.lang.Object[])()(SourceFile:117)
at com.github.nkzawa.engineio.client.transports.WebSocket$3.void run()()(SourceFile:163)
at com.github.nkzawa.thread.EventThread$2.void run()()(SourceFile:75)
at java.util.concurrent.ThreadPoolExecutor.runWorker()(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run()(ThreadPoolExecutor.java:587)
at java.lang.Thread.run()(Thread.java:848)
Exception at class com.github.nkzawa.engineio.client.transports.PollingXHR
Reason: Enumerating String value causes classcastexception at line 192 (tag 0.6.0).
Code changes;
from (0.5.1)
self.onRequestHeaders(headers);
for (Map.Entry<String, String> header : headers.entrySet()) {
xhr.setRequestProperty(header.getKey(), header.getValue());
}
to (0.6.0)
self.onRequestHeaders(headers);
for (Map.Entry<String, List<String>> header : headers.entrySet()) {
for (String v : header.getValue()){
xhr.addRequestProperty(header.getKey(), v);
}
}
We upgrade the engine.io servers from 2.0.2 to 2.1.0 at which point xhr polling transport stopped working for android (v0.8.3). After the first messages are exchanged an error is raised by the client side when the first large message arrives from the server. This causes a disconnection. This is true for all versions of the server up to 3.1.0
The received message looks like it's a short binary message that the android library cannot decode.
it may be related to this change in the parser socketio/engine.io-parser#85
We will keep investigating
Hello, I just found this strange problem, my connection receive EVENT_CLOSE every "pingTimeout" time.
For example, server response:
97:0{"sid":"WWJHwp-pcvQh_7bdAE3t","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":60000}
pingInterval
is 25s, then my app receives EVENT CLOSE
at 50th seconds.
logs:
16:11:40.663 W/System.out: EVENT OPEN
16:12:05.671 I/System.out: ping
16:12:05.730 I/System.out: pong
16:12:30.748 W/System.err: EVENT CLOSE
16:12:35.889 W/System.out: EVENT OPEN
16:13:00.909 I/System.out: ping
16:13:00.960 I/System.out: pong
16:13:25.936 W/System.err: EVENT CLOSE
16:13:31.079 W/System.out: EVENT OPEN
16:13:56.102 I/System.out: ping
16:13:56.162 I/System.out: pong
16:14:21.143 W/System.err: EVENT CLOSE
Seems like ping/pong didn't keep TCP alive.
The version of my library is the latest "0.8.1".
on version 0.8.1
Fatal Exception: java.lang.IllegalStateException: closed
at okhttp3.internal.ws.RealWebSocket.sendMessage(RealWebSocket.java:107)
at io.socket.engineio.client.transports.WebSocket$4.call(WebSocket.java:189)
at io.socket.engineio.parser.Parser.encodePacket(Parser.java:63)
at io.socket.engineio.parser.Parser.encodePacket(Parser.java:42)
at io.socket.engineio.client.transports.WebSocket.write(WebSocket.java:184)
at io.socket.engineio.client.Transport$3.run(Transport.java:108)
at io.socket.thread.EventThread.exec(EventThread.java:55)
at io.socket.engineio.client.Transport.send(Transport.java:103)
at io.socket.engineio.client.Socket.flush(Socket.java:615)
at io.socket.engineio.client.Socket.onDrain(Socket.java:606)
at io.socket.engineio.client.Socket.access$1100(Socket.java:31)
at io.socket.engineio.client.Socket$6.call(Socket.java:308)
at io.socket.emitter.Emitter.emit(Emitter.java:117)
Web Sockets are now a stable feature of OkHttp.
In onFailure, the response is nullable, but the onError use it without checking.
@Override
public void onFailure(final IOException e, final Response response) {
EventThread.exec(new Runnable() {
@Override
public void run() {
self.onError("websocket error " + (response != null ? response.toString() : ""), e);
}
});
}
How can I set a custom SSLEngine? It is possible to prepare something static? Like java has "HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());"?
How to send custom headers from the java client as mentioned here in the docs?
I found in battery mode there is no heartbeat ping anymore and the connection will lost soon.
I also found may caused by the ThreadScheduledExecutor does not work on Android 5.1.
Please, update okhttp version to last version (currently 3.4.1)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.