index.html 679 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>ws test</title>
  6. <script src="data.js"></script>
  7. </head>
  8. <body>
  9. <script>
  10. function on_ws_msg(bin){
  11. var j = BIN.hdr.b2j(bin);
  12. console.log(j);
  13. var b = BIN.hdr.j2b(j);
  14. console.log(b);
  15. ws.send(b);
  16. }
  17. function ws_hdr(){
  18. var proto = window.location.protocol,ws;
  19. if (proto == 'https:'){
  20. ws = 'wss://';
  21. }else{
  22. ws = 'ws://';
  23. }
  24. return ws;
  25. }
  26. ws = new WS("ws://localhost:8888/websocket",on_ws_msg);
  27. </script>
  28. </body>
  29. </html>