开发者

Erlang web-distribution

On non-web based chat system the server distinguishes its clients by their PIDs, right? And what should be used to disting开发者_运维问答uish the clients on web-based chat system?

Thnx in advance


The fact that you're using a web server shouldn't change much about your model. You're still building chat. You also don't want to make your chats tied too deeply to the process that is managing their HTTP connection. HTTP connections are ephemeral, even if everything is going well and you're using long polling there's no guarantee that the connection will be re-used with Keep-Alive for the next long poll. The user might also want to open up the same chat in multiple browser windows, multiple computers, whatever.

I haven't looked closely at any of these but you're not the first person that has built web chat with Erlang:

  • http://chrismoos.com/2009/09/28/building-an-erlang-chat-server-with-comet-part-1/
  • http://www.erlang-factory.com/upload/presentations/31/EugeneLetuchy-ErlangatFacebook.pdf
  • http://yoan.dosimple.ch/blog/2008/05/15/
  • https://github.com/yrashk/socket.io-erlang (more of a general tool for this sort of thing, not chat specifically)
  • https://github.com/rvirding/chat_demo (as seen above)


I think the confusion comes from the notion that a Erlang server process must stay alive for every individual client. It can, but Mochiweb doesn't do that by default if I'm not mistaken. It just spawns a new process for every request. If you would like to have a long lived bidirectional client <-> server process connection you can do that for example by;

  • sending a client identifier with every request and map that to a long-lived process on the server. The process will maintain servers state and you can call methods on it. It's still pull and not push though.
  • use the web socket implementations. Not sure if Mochiweb has one, but other Erlang HTTP servers like Misultin and Yaws provide one. For a web based chat system I believe web sockets would be a great fit.


For a very trivial example of a web-based chat system using websockets and Misultin you can check out this chat demo. It was written to demonstrate an idea and is not very elegant, but it does work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜