ws.html 567 B

12345678910111213141516171819202122232425
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>ws client</title>
  5. </head>
  6. <body>
  7. <script type="text/javascript">
  8. let ws = new WebSocket('ws://localhost:8001')
  9. ws.onopen = () => {
  10. console.log('connection opened')
  11. }
  12. ws.onclose = () => {
  13. console.log('connection closed')
  14. }
  15. ws.onmessage = (ev) => {
  16. console.log('received:' + ev)
  17. }
  18. ws.send(JSON.stringify({a: 1, b: 2}))
  19. </script>
  20. </body>
  21. </html>