如何解析NODEJS+WEBSOCKET中连接信息?

nodejs代码:

nodejsvar wsc = [];
var server = require("http").createServer();
var ws = require('ws');

server.listen(3000);
wss = new ws.Server({
    "server" : server
});
wss.on("connection", function(connection) {
    /* 如何能知道CONNECTION的客户端IP地址?URL等信息? */
    console.log("INFO:输入[" + connection + "]");
    /* 2015/6/3 */
    wsc.push(connection);
    if (wsc.length > 1) {
        data = JSON.stringify({
            "event" : "login"
        });
        connection.send(data);
    }
    connection.on("message", function(message) {
        for ( var int = 0; int < wsc.length; int++) {
            try {
                if (wsc[int] != connection) {
                    wsc[int].send(message);
                }
            } catch (e) {
            }
        }
    });
});
阅读 4.4k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题