socket io tutorial - Listening to internal and custom events - socket io android - socket io client
Listening to internal and custom events
Server Syntaxclick below button to copy the code. By Socket tutorial team
var io = require('Socket io')(80);
io.on('connection', function (mysocket) {
//custom event called `private message`
mysocket.on('private message', function (from, msg) {
console.log('I received a private message by ', from, ' saying ', msg);
});
//internal `disconnect` event fired, when a socket disconnects
mysocket.on('disconnect', function () {
console.log('user disconnected');
});
});click below button to copy the code. By Socket tutorial team
Client syntax:
var mysocket = io('http://example.com');
mysocket.on('private message', function (data) {
console.log(data);
});