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

Loïc Hoguin essen@REDACTED
Sat Aug 17 10:10:41 CEST 2013

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

More information about the erlang-questions mailing list