[erlang-questions] [99s-extend] How to broadcaset with ranch?

Sean Cribbs <>
Wed Aug 21 05:18:19 CEST 2013


This is exactly the sort of thing gen_event is for. I would make each
server process register a handler at startup using
gen_event:add_sup_handler() and then have the handle_event callback simply
relay the event to the server processes. Yes, gproc can do this, but why
incur its extra features and overhead?


On Sat, Aug 17, 2013 at 3:10 AM, Loïc Hoguin <> wrote:

> On 08/17/2013 10:00 AM, Bin Wang wrote:
>
>> Hi,
>>
>> I'm new to ranch. In my application, I need to send some message to
>> all connections. So I'd like to know can I get all connections from
>> ranch, so I could use Transport:send to send them, or I must manage
>> all the created connections by myself? Or is there any other better
>> way?
>>
>
> The best way to do that is on your end, using gproc properties. When the
> connection is accepted, register the process with the property and use the
> property to send messages to all processes. You don't need to unregister
> when the connection ends, gproc does that automatically.
>
> The hackish way to do that would be to call supervisor:which_children on
> the ranch_conns_sup supervisor of your listener, but that will slow down
> the accepting of new connections, so don't do this if you need high accept
> rates.
>
> --
> Loïc Hoguin
> Erlang Cowboy
> Nine Nines
> http://ninenines.eu
>
> ______________________________**_________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/**listinfo/erlang-questions<http://erlang.org/mailman/listinfo/erlang-questions>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130820/b203ebe2/attachment.html>


More information about the erlang-questions mailing list