Code Monkey home page Code Monkey logo

engine.io-client-java's Introduction

Engine.IO-client Java

Build Status

This is the Engine.IO Client Library for Java, which is simply ported from the JavaScript client.

See also: Socket.IO-client Java

Table of content

Compatibility

Client version Engine.IO server Socket.IO server
0.9.x 1.x 1.x
1.x 3.x 2.x
2.x 4.x 3.x

Installation

The latest artifact is available on Maven Central.

Maven

Add the following dependency to your pom.xml.

<dependencies>
  <dependency>
    <groupId>io.socket</groupId>
    <artifactId>engine.io-client</artifactId>
    <version>2.1.0</version>
  </dependency>
</dependencies>

Gradle

Add it as a gradle dependency for Android Studio, in build.gradle:

compile ('io.socket:engine.io-client:2.1.0') {
  // excluding org.json which is provided by Android
  exclude group: 'org.json', module: 'json'
}

Usage

Engine.IO-client Java has the similar api with the JS client. You can use Socket to connect:

socket = new Socket("ws://localhost");
socket.on(Socket.EVENT_OPEN, new Emitter.Listener() {
  @Override
  public void call(Object... args) {
    socket.send("hi");
    socket.close();
  }
});
socket.open();

You can listen events as follows:

socket.on(Socket.EVENT_MESSAGE, new Emitter.Listener() {
  @Override
  public void call(Object... args) {
    String data = (String)args[0];
  }
}).on(Socket.EVENT_ERROR, new Emitter.Listener() {
  @Override
  public void call(Object... args) {
    Exception err = (Exception)args[0];
  }
});

How to set options:

opts = new Socket.Options();
opts.transports = new String[] {WebSocket.NAME};

socket = new Socket(opts);

Sending and receiving binary data:

socket = new Socket();
socket.on(Socket.EVENT_OPEN, new Emitter.Listener() {
  @Override
  public void call(Object... args) {
    // send binary data
    byte[] data = new byte[42];
    socket.send(data);
  }
}).on(Socket.EVENT_MESSAGE, new Emitter.Listener() {
  @Override
  public void call(Object... args) {
    // receive binary data
    byte[] data = (byte[])args[0];
  }
});

Use custom SSL settings:

OkHttpClient okHttpClient = new OkHttpClient.Builder()
    .hostnameVerifier(myHostnameVerifier)
    .sslSocketFactory(mySSLContext.getSocketFactory(), myX509TrustManager)
    .build();

// default SSLContext for all sockets
Socket.setDefaultOkHttpWebSocketFactory(okHttpClient);
Socket.setDefaultOkHttpCallFactory(okHttpClient);

// set as an option
opts = new Socket.Options();
opts.callFactory = okHttpClient;
opts.webSocketFactory = okHttpClient;
socket = new Socket(opts);

Features

This library supports all of the features the JS client does, including events, options and upgrading transport. Android is fully supported.

License

MIT

engine.io-client-java's People

Contributors

akshat-goel avatar b95505017 avatar darrachequesne avatar dave-r12 avatar dependabot[bot] avatar erikogenvik avatar eugene-kudelevsky avatar georgekankava avatar hellpf avatar nkzawa avatar seongugjung avatar seratch avatar sergio91pt avatar shaacker avatar surlemur-zuehlke avatar valodzka avatar vicv avatar wzurita avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

engine.io-client-java's Issues

Is there an API upgrade guide?

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.

Hang-up on application close

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)

Cant find some fields in io.socket.engineio.client$Transport

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;
}

The Polling XHR class is disconecting from the HttpURLConnection before closing the streams

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

Disconnect in a few seconds!

Disconnect in a few seconds after I connect the service!
Why? What need me setting?
And I found it disconnect in 10 seconds.

Establishing connection - problems

Hi,
I am getting the following error while trying the example.
What am I missing?

This is the server code:

        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

Problem with connections through proxy

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?

Android connection close every double 'pingInterval' seconds

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".

Cannot use a custom path

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 /:

this.path = (opts.path != null ? opts.path : "/engine.io").replaceAll("/$", "") + "/";

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.

socket with channel, xhr poll error

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.

NullPointerException in Websocket.java

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);
                    }
                });
            }

Socket transports now throw IllegalArgumentException due to new OkHttp changes (ws/wss not allowd)

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.

Improper creation of OkHttpClient in Websocket.java probably causing Out Of Memory exceptions

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:

  1. square/okhttp#2846
  2. https://square.github.io/okhttp/3.x/okhttp/okhttp3/OkHttpClient.html
  3. Socket.io Java client use this library and it is causing OOM's in them. socketio/socket.io-client-java#315

engine.io-client-java 0.6.1 -> 'websocket error' -- SocketTimeoutException

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?

allowRequest Error code read from android

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

crash when there's error connecting to server

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)

Issue with checksum generated by Artifactory for engine.io pom

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:

  1. is the mapping right between socket.io(0.5.2) and engine.io(0.5.1) clients?
  2. Who generates the checksum and what contributes to it?

Issue in receiving Uni cast

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.

socket can not parse query parameter in URL

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.

Cant find some fields in

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;
}

RejectedExecutionException Occured in onMessage.

State of a socket

Could we please have a socket.isOpen() or socket.isOpening() to programmatically check the health of the socket? Thanks!

0.6.2 still requires OkHttp 2.5.0

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.

Failed polling transport kills websocket transport

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

JNI ERROR (app bug): weak global reference table overflow (max=51200) io.socket.thread.EventThread??

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)

NullPointerException in engineio parser callback

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)

WARNING: Dependency org.json:json:20090211 is ignored for debug

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.

0.8.0 not available on Maven

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'
    }

java.lang.IllegalStateException: Unable to take ownership of connection from okhttp when .connect fails.

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.

IllegalStateException "closed" on sending Message

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)

java.lang.ClassCastException: java.lang.String cannot be cast to java.util.List

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);
            }
        }

Attempt to invoke virtual method 'java.lang.String okhttp3.MediaType.toString()' on a null object reference

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: ZenFone 4 (A450CG)
OS: 4.4.2

Device: HTC One E9 dual sim
OS: 5.0.2

EngineIOException: xhr poll error

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();

WebSocket not correctly closed in case of exceptions from okhttp3 web socket

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.

IndexOutOfBoundsException on decoding payload

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)

Polling broken with android 0.8.3 and server >= 2.1.0

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

SSLEngine

How can I set a custom SSLEngine? It is possible to prepare something static? Like java has "HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());"?

Invalid continuation byte

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"

No action in Desktop client

I was using io.socket:socket.o-client:0.6.1 which works on Desktop & Android but not iOS because of this issue:

robovm/robovm#1153

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?

Publish new release with updated OkHttp3 version

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.