new to erlang: need ideas for server software

Chris Double chris.double@REDACTED
Thu Aug 17 11:30:25 CEST 2006


On 8/17/06, Joe Armstrong (TN/EAB) <joe.armstrong@REDACTED> wrote:
>
> cometd looks to be a ideal application for Erlang.

There is a mailing list for discussion of cometd implementations:

http://groups.google.com/group/cometd-dev

And users:

http://groups.google.com/group/cometd-users

I've also written similar stuff. My current incarnation allows
lightweight processes on the browser using CPS transformed javascript.
An erlang style messaging system is built on top of that allowing
browser processes to send and receive messages to each other and to
the server.

So a browser process can send a message to a suitably registered
server process. A server process can also send a message to a browser
process, or broadcast to all browser processes. This uses a comet
style connection - either XMLHttpRequest polling or iframes.

This made it trivial to write a chat application. I just keep track of
all browser processes on the server as the browser connections. When a
chat message is sent the browser process sends the message to a
process on the server and it broadcasts it to a processes on all
clients.

Browser processes look like:

function alerter() {
  while(true) {
    var msg = receive->();
    document.getElementById("messages").value += (msg + "\n")
  }
}
register_process("p1", spawn(alerter));

The ->() syntax is a yielding function call. It transforms via CPS at
load time in the browser into javascript which calls a function that
blocks waiting for a message. On receipt of the message it calls the
continuation which is the resumption after the ->() call.

That message can come from a server process or from another browser
(which is routed via the server).

It works quite well. More here:

http://www.bluishcoder.co.nz/2006/08/factor-web-framework.html

Although currently the back end is written in Factor I do plan to do
an Erlang back end as the javascript side will be constant across
implementations. The message sending code is just JSON encoded
objects.

Chris.
-- 
http://www.bluishcoder.co.nz



More information about the erlang-questions mailing list