index.html 752 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. j.chall = 1;
  13. j.type = PKT_TYPE.PKT_TYPE_CH_ALL;
  14. console.log(j);
  15. var b = BIN.hdr.j2b(j);
  16. console.log(b);
  17. ws.send(b);
  18. }
  19. function ws_hdr(){
  20. var proto = window.location.protocol,ws;
  21. if (proto == 'https:'){
  22. ws = 'wss://';
  23. }else{
  24. ws = 'ws://';
  25. }
  26. return ws;
  27. }
  28. ws = new WS("ws://localhost:8888/websocket",on_ws_msg);
  29. </script>
  30. </body>
  31. </html>