迭代websocketpp服务器中的所有连接

时间:2015-11-07 18:36:05

标签: c++ websocket

我修改了“扩展连接存储”'示例位于http://www.zaphoyd.com/websocketpp/manual/common-patterns/storing-connection-specificsession-information,可以更新从客户端发送的一些数据。当数据发生变化时,我希望将其传播到所有连接的客户端。我想迭代所有连接,但在底部文档说明'注意,此示例无法枚举所有连接。'。

我应该使用http://www.zaphoyd.com/websocketpp/manual/common-patterns/server-initiated-messages上的示例吗?

伪代码:

void on_message(connection_hdl hdl, server::message_ptr msg) {
    if (jdata["type"] == "update") {
        for (auto it : connections) {
            m_server.send(hdl, msg);
        }
    }
}

1 个答案:

答案 0 :(得分:0)

与孩子一起看电视的时间是优质时间。我突然想起了websocketpp上的其他例子:

unpack_rm_corrupted() {
    corrupted='a'
    while [ "$corrupted" ]; do
        corrupted=$(                                  \
        git unpack-objects -r < "$1" 2>&1 >/dev/null \
            | grep 'stored in'                          \
            | sed -r 's:.*(\.git/.*)\).*:\1:'           \
        )
        echo "$corrupted"
        rm -f "$corrupted"
    done
}

if [ -z "$1" ]  || [ ! -d "$1" ]; then
    echo "'$1' is not a directory. Please provide the directory of the git repo"
    exit 1
fi

for p in $1/objects/pack/pack-*.pack; do
    echo "$p"
    unpack_rm_corrupted "$p"
done