I isue a SUBSCRIBE and I get back a subscribe reply as expected and then the websocket closes straight away. I was expecting it to stay up similarly to issuing the same SUBSCRIBE through a webbrowser where it stays open and recieves data as PUBLISH commands are issued.
(NB: Newbie here)
I isue a SUBSCRIBE and I get back a subscribe reply as expected and then the websocket closes straight away. I was expecting it to stay up similarly to issuing the same SUBSCRIBE through a webbrowser where it stays open and recieves data as PUBLISH commands are issued.
What am I missing?
var jsonSocket = new WebSocket("ws://127.0.0.1:7379/.json"); jsonSocket.onopen = function() { console.log("JSON socket connected!"); jsonSocket.send(JSON.stringify(["SUBSCRIBE", "test"])); }; jsonSocket.onmessage = function(messageEvent) { console.log("JSON received:", messageEvent.data); }; jsonSocket.onclose = function() { console.log("JSON closed"); };
Console output:
JSON socket connected! test.html:55 JSON received: {"SUBSCRIBE":["subscribe","test",1]} test.html:60 JSON closed