[erlang-questions] NineNines Bullet

40 views
Skip to first unread message

Lee Sylvester

unread,
Apr 2, 2013, 4:08:34 PM4/2/13
to erlang-questions@erlang.org Questions
Hey guys,

Does anyone here know of a good tutorial or chat example of NineNines Bullet handler for Cowboy?

Thanks loads,
Lee
_______________________________________________
erlang-questions mailing list
erlang-q...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions

Loïc Hoguin

unread,
Apr 2, 2013, 4:23:21 PM4/2/13
to Lee Sylvester, erlang-questions@erlang.org Questions
On 04/02/2013 10:08 PM, Lee Sylvester wrote:
> Hey guys,
>
> Does anyone here know of a good tutorial or chat example of NineNines Bullet handler for Cowboy?

Have you looked at the clock example that comes with it? Building a chat
on top of that is just making connection processes talk to each other
using a registry like gproc or a gen_server that dispatches messages.

--
Loïc Hoguin
Erlang Cowboy
Nine Nines
http://ninenines.eu

Lee Sylvester

unread,
Apr 2, 2013, 4:27:47 PM4/2/13
to Loïc Hoguin, erlang-questions@erlang.org Questions
Hi Loïc,

Yes, I spotted that. It just doesn't seem very explanatory. I was hoping for something a little bit more extensive. Preferably something that used the concept of rooms. The NineNines support page for Bullet is also a little thin… :-S I guess I'm too much of a noob.

Thanks,
Lee

Loïc Hoguin

unread,
Apr 2, 2013, 4:35:27 PM4/2/13
to Lee Sylvester, erlang-questions@erlang.org Questions
Rooms is a bit out of scope. I agree it could use some more
documentation though.

The basic idea is that when your process connects its pid is added to a
list somewhere (gproc, gen_server, anything else). When a message is
sent to the room, all pids in the list receive it. You can also
broadcast when someone enters or leave the room. And you remove the pid
from the list when it's gone (using monitors for example).

Lee Sylvester

unread,
Apr 2, 2013, 5:00:09 PM4/2/13
to Loïc Hoguin, erlang-questions@erlang.org Questions
Yes, that's how I was seeing it. Mentally at least. I've got a similar thing built in Go which I want to port to Erlang using Bullet. Go's websocket implementation is quite far from complete and has been a headache to work with. I'm hoping to have something a lot more robust with Erlang.

So, let me get this straight… init handles the connection setup and terminate handles the teardown. So, I can make calls in those two functions to add the user to a room collection or removing her.

What are the differences between stream and info? When do those come into play? I'm assuming one (stream?) is invoked when data is sent from the end user. Is that right?

Thanks,
Lee

Lee Sylvester

unread,
Apr 2, 2013, 5:09:25 PM4/2/13
to Loïc Hoguin, erlang-questions@erlang.org Questions
Another thing; I'm guessing returning {reply,…} from the stream function sends a reply to the user for that connection and returning {ok,…} doesn't. How, though, do I send a message to some other specific user, providing I have their Pid?

Thanks,
Lee

Loïc Hoguin

unread,
Apr 2, 2013, 5:09:31 PM4/2/13
to Lee Sylvester, erlang-questions@erlang.org Questions
That's the idea.

As for the rest:
stream = message from the browser, info = message from erlang

Loïc Hoguin

unread,
Apr 2, 2013, 5:10:25 PM4/2/13
to Lee Sylvester, erlang-questions@erlang.org Questions
Pid ! {you_got_mail, TheMessage} and receive it in info:

info({you_got_mail, TheMessage}, ...) ->
{reply, TheMessage, ...};

Lee Sylvester

unread,
Apr 2, 2013, 5:10:57 PM4/2/13
to Loïc Hoguin, erlang-questions@erlang.org Questions
I see, so info handles messages I've sent straight to the Pid using standard erlang messaging. If I return {reply,…} to that function, does it send the returned data to the user associated with that info function?

Thanks,
Lee

Lee Sylvester

unread,
Apr 2, 2013, 5:11:27 PM4/2/13
to Loïc Hoguin, erlang-questions@erlang.org Questions
Perfect :-) Thanks Loïc.

Lee
Reply all
Reply to author
Forward
0 new messages