NodeJS建立websocket连接及消息广播
var ws=require("nodejs-websocket");
var express=require('express');
var app=express();
//消息广播
function broadcast(server, msg)
{
server.connections.forEach(function(conn)
{
conn.sendText(msg)
})
}
//建立websocket链接
var server=ws.createServer(function(connection)
{
connection.on('text',function(result)
{
})
connection.on('connect',function(code)
{
console.log("开启链接",code);
})
connection.on('close',function(code)
{
console.log("关
共有 0 条评论