Node.js+webSocket
// 引入WebSocket模块
var ws = require('nodejs-websocket')
var PORT = 3030
var server = ws.createServer(function(conn){
console.log('新连接')
conn.on("text",function(str){
console.log("接受数据"+str)
conn.sendText("返回数据:"+str)
})
conn.on("close",function(code,reason){
console.log("关闭连接")
})
conn.on("error",function(err){
console.log(err)
})
}).listen(PORT)
console.log('websocket 监听端口: ' + PORT)
github地址:https://github.com/Rossy11/node