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

Support websockets #27

Open
ulrikstrid opened this issue Oct 30, 2019 · 1 comment
Open

Support websockets #27

ulrikstrid opened this issue Oct 30, 2019 · 1 comment

Comments

@ulrikstrid
Copy link
Collaborator

We need a way to support websockets.

For httpaf we can use this to upgrade the connection: https://github.com/anmonteiro/httpaf/blob/fork/lib/httpaf.mli#L640.
For h2 we can just take the TCP connection and do the same thing, if we want to support it at all.

The biggest problem is how to build the API.
My current thought is that we should add a function to the request to get hold of a socket (basically a way to send and receive data, maybe via Lwt_stream.t). And then to close the connection we return the response, but that might feel weird since we've actually already responded.
Another solution would be to have a Socket body that does the same thing but then the term body is overloaded.

@yawaramin
Copy link

yawaramin commented Dec 25, 2019

How about something like:

// Echo websocket
Morph.Response.webSocket("/path", (send, recv) =>
  Lwt_stream.iter(recv, string => {
    print_endline({|Received data from client: "|} ++ string ++ {|"|});
    send(if (string == "close") None else Some(string));
  }
);

That's a really simplified version but I think it gets the idea across.

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

No branches or pull requests

2 participants