// 引入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/nodenode