ws.html 819 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>WebSocketTest</title>
  6. </head>
  7. <body>
  8. <div id="sse">
  9. <a href="javascript:WebSocketTest()">运行 WebSocket</a>
  10. </div>
  11. </body>
  12. <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
  13. <script type="text/javascript">
  14. function WebSocketTest() {
  15. var ws = new WebSocket("ws://localhost:7981/websocket?ip=&terminal_id=A00_01&version=chrome-socket");
  16. ws.onopen = function () {
  17. console.log("message sending");
  18. ws.send("test send abc");
  19. };
  20. ws.onmessage = function (evt) {
  21. var received_msg = evt.data;
  22. console.log("received msg" + received_msg);
  23. };
  24. ws.onclose = function () {
  25. alert("close");
  26. };
  27. }
  28. </script>
  29. </html>