[erlang-questions] WebSocket impl for Mochiweb

Joe Armstrong <>
Tue Dec 15 09:50:24 CET 2009


Sweet.  You have a nice way of encapsulating the interface in a Fun.

Now all we need is a javascript IRC client that talks web-sockets
and a server that understands the IRC protocol, and a backend based on a DHT
(like riak) and we have a high scalable robust p2p architecture for
chat/whatever !!!

I can contribute a IRC server that is pretty basic (it's almost done)

Just need riak integration and a javascript client.

/Joe



On Tue, Dec 15, 2009 at 12:33 AM, Dave Bryson <> wrote:
> Like many others, the WebSocket bug bit me. So I've implemented a little add
> on for Mochiweb. Basically the module wraps the mochiweb_socket_server and
> allows you to write WebSocket based apps similar to how you'd write a
> regular web application in Mochiweb.  Here's an example from the source
> code:
>
> -module(basic_websocket).
> -export([start/1, stop/0, loop/1]).
>
> start(Options) ->
>    Loop = fun (WebSocket) ->
>                   ?MODULE:loop(WebSocket)
>           end,
>    mochiweb_websocket:start([{name, ?MODULE}, {loop, Loop} | Options]).
>
> stop() ->
>    mochiweb_websocket:stop(?MODULE).
>
> loop(WebSocket) ->
>    %% Get the data sent from the client
>    Data = WebSocket:get_data(),
>
>    %% This is a little echo service.  The "client-connected" is just our
> implementation
>    %% for this example.  See priv/www/index.html
>    case Data of
>        "client-connected" ->
>            WebSocket:send("You are connected!");
>        %% Other messages go here
>        Other ->
>            Msg = "You Said: " ++ Other,
>            WebSocket:send(Msg)
>    end.
>
>
> You can find the source here:  http://github.com/davebryson/erlang_websocket
>
> This is just a quick bit of code, but it seems to work fine for playing
> around.
>
> Dave
>
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org
>
>


More information about the erlang-questions mailing list