[erlang-questions] Push a message to cowboy websockets

Magnus Klaar <>
Sat Apr 7 18:20:51 CEST 2012


Hi!

All names registered for a process will be cleaned up when the process
exits. Unless you need to switch between receiving broadcasted messages and
not mid-flight there is no need to unregister the property/name manually.
If you're looking for the same effect in the middle of the lifetime of a
process the gproc:goodbye function can be used to unregister all names.

MVH Magnus

On Sat, Apr 7, 2012 at 4:56 PM, Barco You <> wrote:

> thank you very much you all.
>
> But next question: how can I delete a client from the broadcast pool,
> because the gproc has only the API to unregister a process by "key" -
> unreg(Key) - and can not find unregister by Pid().
>
> Best regards,
> Barco
>
>
> On Sat, Apr 7, 2012 at 10:26 PM, Magnus Klaar <>wrote:
>
>> Hi!
>>
>> Insert a function clause to filter out these messages to the
>> websocket_info/3 function. You are already including the process-id of the
>> sending process in your broadcast/1 function, we can use that to filters
>> out messages sent from self(). In practice, you _may_ want to use a logical
>> id to perform this filtering rather than reusing the process-id of the
>> connection that happened to be connected to a client at the time.
>>
>> websocket_info({Pid, {_Module, ?BC}, _Msg}, Req, State) when Pid =:=
>> self() ->
>>    {ok, Req, State, hibernate};
>> websocket_info({_Pid, {_Module, ?BC}, Msg}, Req, State) ->
>>     {reply, {text, <<Msg>>}, Req, State, hibernate}.
>>
>> MVH Magnus
>>
>> On Sat, Apr 7, 2012 at 4:13 PM, Barco You <> wrote:
>>
>>> Hi Magnus,
>>>
>>> Thank you very much!
>>>
>>> Then, if broadcasting to all other clients except self, how to do it
>>> with gproc?
>>>
>>> Regards,
>>> Barco
>>>
>>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120407/643e66e2/attachment.html>


More information about the erlang-questions mailing list