vendredi 27 février 2015

NodeJs io.socket.SocketIOException: Error while handshaking

i'm trying to write simple application with nodejs and express.io after reading some express.io document i'm find simple sample with Broadcust name, after run this below code in command line and opening http://localhost:7076 in browser i dont get any error, but i want to try send request from android client to that but i get error:


server.js



app = require('express.io')()
app.http().io()

// Broadcast the new visitor event on ready route.
app.io.route('ready', function(req) {
req.io.broadcast('new visitor')
})

// Send client html.
app.get('/', function(req, res) {
res.sendfile(__dirname + '/client.html')
})

app.listen(7076)


Error:



io.socket.SocketIOException: Error while handshaking


my android code:



SocketIO socketio = null;
try {
socketio = new SocketIO(SERVER_ADDRESS);
} catch (MalformedURLException e) {
e.printStackTrace();
}
socketio.connect(new IOCallback() {
@Override
public void onMessage(JSONObject json, IOAcknowledge ack) {
try {
Log.e("Server said:" , json.toString(2));
} catch (JSONException e) {
e.printStackTrace();
}
}

@Override
public void onMessage(String data, IOAcknowledge ack) {
Log.e("Server said: " , data);
}

@Override
public void onError(SocketIOException socketIOException) {
Log.e("an Error occured","");
socketIOException.printStackTrace();
}

@Override
public void onDisconnect() {
Log.e("Connection terminated.","");
}

@Override
public void onConnect() {
Log.e("Connection established","");
}

@Override
public void on(String event, IOAcknowledge ack, Object... args) {
Log.e("Server triggered event '" , event + "'");
}
});

socketio.emit("new visitor", "user1");

Aucun commentaire:

Enregistrer un commentaire