misultin adds websocket support

Roberto Ostinelli <>
Wed Jan 20 15:57:00 CET 2010


dear all,

after the well-known and inspiring post from joe, i've just finished adding
websocket support to misultin http://code.google.com/p/misultin/

usage is pretty straightforward, and a brief explanation can be found here:

http://www.ostinelli.net/misultin-erlang-and-websockets/

basically, all you need to define is a function which is spawned by misultin
when websocket requests are received, such as handle_websocket/1:

handle_websocket(Ws) ->
   receive
      {browser, Data} ->
         Ws:send(["received '", Data, "'"]),
         handle_websocket(Ws);
      _Ignore ->
         handle_websocket(Ws)
   after 5000 ->
      Ws:send("pushing!"),
      handle_websocket(Ws)
   end.

Data coming from a browser will be sent to this process and will have the
message format {browser, Data}, where Data is a string(). If you need to
send data to the browser, you may do so by using the parametrized function
Ws:send(Data), Data being a string() or an iolist().

comments welcomed, as usual.

cheers,

r.


More information about the erlang-questions mailing list