I'm trying to understand how web sockets work. I do have basic understanding that unlike AJAX in web sockets connection is always open which is convenient for real time applications.
This is very basic example using socks:
var sock = new SockJS('http://mydomain.com/my_prefix');
sock.onopen = function() {
console.log('open');
};
sock.send("request to send (JSON)");
sock.onmessage = function(e) {
console.log('message', e.data);
};
sock.onclose = function() {
console.log('close');
};
Requirement: I have multiple widgets to display real time data so I want each widget to subscribe to a JSON request/service, keep connection open and unsubscribe whenever required.
Question: In this case how do we handle multiple requests, like we do with typical AJAX setup?
I'll appreciate if someone can guide me to correct direction, give me an example or a link to tutorial.
Anyone?