socketIo.html 884 B

1234567891011121314151617181920212223242526
  1. <!DOCTYPE html>
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  5. <title></title>
  6. <script src="js/socket.io.min.js"></script>
  7. </head>
  8. <body>
  9. <script>
  10. var socket = io.connect("ws://192.168.3.92:8088", { path: "onlinewebsocket/123456" })
  11. socket.on('error', function (data) {
  12. console.log(JSON.stringify(data) + ' - error');
  13. });
  14. socket.on('disconnect', function (data) {
  15. //失去连接的事件
  16. console.log(JSON.stringify(data) + ' - disconnect');
  17. });
  18. socket.on('reconnect', function (data) {
  19. //重新连接的事件
  20. console.log(JSON.stringify(data) + ' - reconnect');
  21. socket.emit('userReg', userMsg);
  22. });
  23. socket.emit('userReg', "123");
  24. </script>
  25. </body>
  26. </html>