[erlang-questions] Push a message to cowboy websockets

Barco You barcojie@REDACTED
Sat Apr 7 16:56:46 CEST 2012


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 <magnus.klaar@REDACTED>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 <barcojie@REDACTED> 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/fc08b492/attachment.htm>


More information about the erlang-questions mailing list