Reputation: 2271
I have been working in a chat app using nodejs and socket.io. I already have an Android client that works perfect in this schema. I started to use express.io instead of use express an socket.io separately. Everything works well except for my Android client. Im using https://github.com/socketio/socket.io-client-java socket client in Android, but my app never connect to my socket server.
I received the following error: io.socket.engineio.client.EngineIOException: server error
Does anybody knows something about this issue?
Server side config:
var express = require('express.io');
var path = require('path');
var logger = require('morgan');
var bodyParser = require('body-parser');
var multer = require('multer');
var app = express();
app.http().io()
app.io.route('storeClientInfo', function(req) {
req.io.join(req.io.request.data.customId);
});
app.io.route('enviar_room', function(req) {
app.io.room(req.params.correo).broadcast('new visitor');
});
// Start the server
app.set('port', process.env.PORT || 3000);
var server = app.listen(app.get('port'), function() {
console.log('Express server listening on port ' + server.address().port);
});
Android side:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
mSocket = IO.socket(LoginActivity.URL_HOST);
mSocket.on(Socket.EVENT_CONNECT_ERROR, onConnectError);
mSocket.on("new visitor",onNuevoMensaje);
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
private Emitter.Listener onConnectError = new Emitter.Listener() {
@Override
public void call(Object... args) {
Log.d("SocketMsg: ", args[0].toString());
for (Object o : args) {
Log.i("IO " + Socket.EVENT_CONNECT_ERROR, o.toString());
}
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(),
"CONNECT ERROR", Toast.LENGTH_LONG).show();
}
});
}
};
Currently I already have a Angularjs web version running with my server. The problem is that in Android i always received Socket.EVENT_CONNECT_ERROR.
Upvotes: 0
Views: 380
Reputation: 2271
After two days of tests I found that the problem was that Express.io include a socket.io version 0.9.6. The socket.io-client-java library (https://github.com/socketio/socket.io-client-java) support socket.io 1.x or later. I manually changed the socket.io version on Express.io to the 1.3.7 version. I just had to modify some parts of the code on the Express library.
Upvotes: 0