Socket.io-client-java: io.socket.engineio.client.EngineIOException: server error

Created on 10 Dec 2018  路  5Comments  路  Source: socketio/socket.io-client-java

Socket IO server version: 2.2.0

"dependencies": {
    "socket.io": "2.2.0",
    "express": "4.16.4"
  },

Server code

var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);

io.on('connection', function (socket) {

  console.log('connected!', socket.id);
  socket.join('cobra'); // Join cobra group.

  socket.on('message', function (data) {
        console.log('message', data);
        socket.broadcast.to('cobra').emit('message', data);
  });

  socket.on('disconnect', function () {
    console.log('disconnected!', socket.id);
    socket.leave('cobra');
  });

});

http.listen(process.env.PORT || 3000, process.env.IP || "0.0.0.0", function(){
  var addr = http.address();
  console.log("Server listening at", addr.address + ":" + addr.port+" copon!");
});

Android library version: 1.0.0
implementation 'io.socket:socket.io-client:1.0.0'

Android connection code

        try {
            IO.Options opts = new IO.Options();
            opts.forceNew = true;

            mSocket = IO.socket(<fancy_server_url>, opts);
            mSocket.on(Socket.EVENT_CONNECT, onConnect);
            mSocket.on(Socket.EVENT_DISCONNECT, onDisconnect);
            mSocket.on(Socket.EVENT_CONNECT_ERROR, onConnectError);
            mSocket.on(Socket.EVENT_CONNECT_TIMEOUT, onConnectError);
            mSocket.on("message", onNewMessage);
            mSocket.connect();

        } catch (URISyntaxException e) {
            Log.e(TAG,"URLSyntax exception!");
        }

I am getting this exception as Socket.EVENT_CONNECT_ERROR event:

io.socket.engineio.client.EngineIOException: server error
     at io.socket.engineio.client.Socket.onPacket(Socket.java:547)
     at io.socket.engineio.client.Socket.access$1000(Socket.java:36)
     at io.socket.engineio.client.Socket$5.call(Socket.java:335)
     at io.socket.emitter.Emitter.emit(Emitter.java:117)
     at io.socket.engineio.client.Transport.onPacket(Transport.java:126)
     at io.socket.engineio.client.transports.Polling.access$700(Polling.java:18)
     at io.socket.engineio.client.transports.Polling$2.call(Polling.java:127)
     at io.socket.engineio.parser.Parser.decodePayload(Parser.java:222)
     at io.socket.engineio.client.transports.Polling._onData(Polling.java:135)
     at io.socket.engineio.client.transports.Polling.onData(Polling.java:102)
     at io.socket.engineio.client.transports.PollingXHR$5$1.run(PollingXHR.java:125)
     at io.socket.thread.EventThread$2.run(EventThread.java:80)
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
     at java.lang.Thread.run(Thread.java:818)

I'm able to connect to same server using this socket.io demo tool -> https://amritb.github.io/socketio-client-tool/ but impossible from Android using this libray :/

Most helpful comment

for now, i found the solution,..
the issue is with latest version of socket.io. i just downgraded to "socket.io": "^2.3.0". now it's working.

All 5 comments

Was my fault. I was using Cloud9 server, and to connect from Android is needed to mark the project as "Public".

However two points to take care here:

  • In my opinion, it's not enough clear that the issue is "can't connect with server"
  • Web pages were allowed to connect to server while on private but not with this Android library, so there is any difference there that implies different behavior.

i am also getting the same error
io.socket.engineio.client.EngineIOException: server error
javascript library of socket.io-client is working fine. (tested in ReactiveNative Application)

only issues with java library.
Any resolution ?.

for now, i found the solution,..
the issue is with latest version of socket.io. i just downgraded to "socket.io": "^2.3.0". now it's working.

I don't know why but I downgraded like @Cloudtrackers said above and it worked.

Also, I used these configurations:

  • android:usesCleartextTraffic="true"
  • change localhost into IP
  • server: https://github.com/socketio/socket.io/blob/master/examples/chat/index.js

well for debug or testing okay, but that is not any solution ahah
you should secure your server and configure it to use TLS/SSL
usesCleartextTraffic says that you want to use http instead of https

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sojharo picture sojharo  路  10Comments

jukbot picture jukbot  路  3Comments

RishabhDuttSharma picture RishabhDuttSharma  路  5Comments

arora-arpit picture arora-arpit  路  3Comments

yosuke-furukawa picture yosuke-furukawa  路  8Comments