-
Notifications
You must be signed in to change notification settings - Fork 474
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Websocket support #120
Websocket support #120
Conversation
I haven't reviewed this yet but I just want to say thanks for contributing something that's so complete and tested in production! |
This looks pretty good so far, I want to add some more complete tests and a better example but this looks like it shouldn't be too much trouble to merge in. |
I've made some changes at https://github.com/mochi/mochiweb/tree/websocket – the one thing I'm unsure about here is the paradigm for receiving messages. It seems useful to be able to do something based on events that didn't come via TCP. Basically, this implementation doesn't seem to allow for a "server push", only a request/response model. Am I missing something? |
Maybe example that I provided is a bit misleading. ReplyChannel websocket.erl#L89 is a fun that may be passed to other process and can be used at anytime and any number of times to push data to client. The way that It's done in our comet server is that there is a new process spawned for each connected client. ReplyChannel is passed to this process and PID of this process is held in ws_loop/3 State variable. Thanks that any received data may be passed to this "client process" and if "client process" has any data to push it uses ReplyChannel. I hope that I answered your question and explained it a little bit :) I can write better example if you think it will be helpful. For example: with separate process which will push message every second to each connected client. |
Good point, I'll go ahead and make some changes to the example to demonstrate that use case |
This could use some more comments, but what do you think of this? https://github.com/mochi/mochiweb/blob/websocket/examples/websocket/websocket.erl |
Cool! Websocket chat server written in erlang in about 100 lines :) I think that now this example clearly shows how to implement asynchronous communication using mochiweb_websocket. It's ok for me. |
Referencing #26
Actually I've done some work on implementing websocket in mochiweb. It's based on misultin websocket implementation and mochiweb_http module.
We've been using it on production for over 2 years (as library for comet server) on Brainly group websites and it performs quite well with traffic up to 40k concurrent users.
I just added tests, example of usage and documentation. I'm aware that there still may be need to do some work on this module so I look forward for feedback. :)