[erlang-questions] Push a message to cowboy websockets

Magnus Klaar <>
Sat Apr 7 16:26:02 CEST 2012


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/29eaeb71/attachment.html>


More information about the erlang-questions mailing list