<!DOCTYPE html> <html> <head> <title>Hello WebSocket</title> <link href="/webjars/bootstrap/css/bootstrap.min.css" rel="stylesheet"> <link href="/main.css" rel="stylesheet"> <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.3/socket.io.js"></script> <script> var socket = io(‘http://wechat.daopeng365.com‘); socket.on(‘connect‘, function(){}); socket.emit(‘sendDevnum‘, ‘6961616647311138‘); socket.on(‘messageevent‘, function(data){console.log(data)}); </script> </head> <body> </body> </html>
我们有的时候会遇到客户端和服务器端相互监听的情况,这个时候websocket就派上用场了,socket.io和websocket的区别网上都有,我简单的理解就是socket.io集成了websocket的一切
http://blog.csdn.net/while0/article/details/53930116 websocket和socket.io的区别和理解
下面附上socket.io的简单的api
http://blog.csdn.net/wang8088498/article/details/52194394