var ws = new WebSocket("wss://echo.websocket.org");
ws.onopen = function(evt) {
console.log("Connection open ...");
ws.send("Hello WebSockets!");
};
ws.onmessage = function(evt) {
console.log( "Received Message: " + evt.data);
ws.close();
};
ws.onclose = function(evt) {
console.log("Connection closed.");
};
- @stomp/stompjs
- sockjs-client (sockjs 的client)
<script src="${cms_path}/res/js/sockjs-client/sockjs.min.js"></script>
<script src="${cms_path}/res/js/stomp-websocket/stomp.js"></script>
export function getWebsocketData(){
var stompClient = null;
var socket = new SockJS('http://www.smartiot-china.com:8080/websocket');
stompClient = Stomp.over(socket);
stompClient.connect({}, function (frame) {
console.log('Connected: ' + frame);
stompClient.subscribe('/configMap/{组态id}', function (data) {
var msg=JSON.parse(data.body)
}, {'token': xxx})
}, function (res) {
console.log("error");
console.log(res);
});
stompClient.ws.onclose = function (res) {
console.log('Connection closed!');
console.log(res);
};
}
java 只提供需要更新的点值(全部返回由于点值太多而造成效率低下)
fe 只有当有点值更新时才重新渲染canvas (寻求优化方案)