<html> <head> <title>test</title> <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script> <script src="https://cdn.bootcss.com/socketcluster-client/7.0.1/socketcluster.min.js"></script> <!--<script src="sc_demo.js"></script>--> <script> $(function () { test(); }); var socket = socketCluster.connect( { port: 8088, hostname: "127.0.0.1", path: '/feed/78FF0A0F-34CF-4AA2-9DC2-BD308D3657D2', secure: false }); function test(){ console.log('connected'); var sub = socket.subscribe('zdr-m32'); sub.watch(function (data) { console.log("zdr-m32"); console.log(data); }); var sub2 = socket.subscribe('zdr-domain'); sub2.watch(function (data) { console.log("zdr-domain"); console.log(data); }); } </script> </head> <body> <button type="button" onclick="test()">点击这里</button> </body> </html>