简体   繁体   中英

erlang cowboy websocket- number of open sockets

I have written an Erlang chat backend, using the cowboy module.

I'm trying to figure out how can i log the number of open web sockets connections, that are currently connected.

I have been looking for an answer to this question for a while, and i couldn't find one.

Do you have any idea how it could be done?

Thank you for your time,

Do count your websocket into websocket_init or websocket_handle I write down the information of the public in websocket ets table

Add information websocket about:

websocket_handle({text, Msg}, Req, State) ->
            ets:insert(systbl_websockets, {self(), get_current, other_info}),
            {reply, [{text, <<"ok">>}], Req, State, hibernate};
    end;

Remove information websocket about:

websocket_terminate(_Reason, _Req, _State) ->
    lager:debug("Close connection"),
    ets:delete(systbl_websockets, self()),
    {ok, _Req, _State, shutdown}.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM