Socket.IO allows you to emit and receive custom events. Besides
connect
,message
anddisconnect
, you can emit custom events
Server
io.on('connection', function (socket) { socket.on("msg1", function (from, msg) { console.log('I received a message by ', from, ' saying ', msg); }); });
Client
$(document).ready(function () { var socket = io.connect('http://localhost:14000'); socket.emit("msg1", "Mahmood", "Hello"); });
References
https://socket.io/docs/#Sending-and-receiving-events