Websocket erlang牛仔网插座-开放式插座的数量
我使用cowboy模块编写了一个Erlang聊天后端 我想知道如何记录当前连接的打开的web套接字连接数 我一直在寻找这个问题的答案,但我找不到答案 你知道怎么做吗Websocket erlang牛仔网插座-开放式插座的数量,websocket,erlang,cowboy,Websocket,Erlang,Cowboy,我使用cowboy模块编写了一个Erlang聊天后端 我想知道如何记录当前连接的打开的web套接字连接数 我一直在寻找这个问题的答案,但我找不到答案 你知道怎么做吗 谢谢您的时间,请将您的websocket计入websocket\u init或websocket\u handle 我把公众的信息写在websocketets表格中 添加有关以下内容的信息websocket: websocket_handle({text, Msg}, Req, State) -> et
谢谢您的时间,请将您的websocket计入
websocket\u init
或websocket\u handle
我把公众的信息写在websocketets
表格中
添加有关以下内容的信息websocket:
websocket_handle({text, Msg}, Req, State) ->
ets:insert(systbl_websockets, {self(), get_current, other_info}),
{reply, [{text, <<"ok">>}], Req, State, hibernate};
end;
websocket_terminate(_Reason, _Req, _State) ->
lager:debug("Close connection"),
ets:delete(systbl_websockets, self()),
{ok, _Req, _State, shutdown}.
请将您的websocket计入
websocket\u init
或websocket\u handle
我把公众的信息写在websocketets
表格中
添加有关以下内容的信息websocket:
websocket_handle({text, Msg}, Req, State) ->
ets:insert(systbl_websockets, {self(), get_current, other_info}),
{reply, [{text, <<"ok">>}], Req, State, hibernate};
end;
websocket_terminate(_Reason, _Req, _State) ->
lager:debug("Close connection"),
ets:delete(systbl_websockets, self()),
{ok, _Req, _State, shutdown}.
我已经实现了一个计数器,在所有进程上迭代,初始调用{cowboy_protocol,init,4}这似乎可以正常工作fine@user1668328那个(过程迭代)在技术上听起来有点不可靠。至少,由于牛仔的变化,它可能很容易断裂。我必须说,我更喜欢回答者发布的解决方案。我已经实现了一个计数器,迭代所有进程,初始调用{cowboy_protocol,init,4}这似乎很有效fine@user1668328那个(过程迭代)在技术上听起来有点不可靠。至少,由于牛仔的变化,它可能很容易断裂。我不得不说,我更喜欢回答者发布的解决方案。