Skip to content
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

Merged
merged 7 commits into from
Jan 2, 2014
Merged

Websocket support #120

merged 7 commits into from
Jan 2, 2014

Conversation

k3nn7
Copy link
Contributor

@k3nn7 k3nn7 commented Dec 25, 2013

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. :)

@etrepum
Copy link
Member

etrepum commented Dec 25, 2013

I haven't reviewed this yet but I just want to say thanks for contributing something that's so complete and tested in production!

@etrepum etrepum mentioned this pull request Dec 25, 2013
@etrepum
Copy link
Member

etrepum commented Dec 25, 2013

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.

@etrepum
Copy link
Member

etrepum commented Dec 25, 2013

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?

@k3nn7
Copy link
Contributor Author

k3nn7 commented Dec 26, 2013

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.

@etrepum
Copy link
Member

etrepum commented Dec 26, 2013

Good point, I'll go ahead and make some changes to the example to demonstrate that use case

@etrepum
Copy link
Member

etrepum commented Dec 26, 2013

This could use some more comments, but what do you think of this? https://github.com/mochi/mochiweb/blob/websocket/examples/websocket/websocket.erl

@k3nn7
Copy link
Contributor Author

k3nn7 commented Dec 26, 2013

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.
Btw I might have found a small bug in this example, I'll write about this in comment to commit.

@etrepum etrepum merged commit 7ba3196 into mochi:master Jan 2, 2014
@k3nn7 k3nn7 deleted the websocket branch January 3, 2014 23:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants