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

how to upgrade an http server to websockets? #308

Closed
dckc opened this issue Dec 31, 2019 · 3 comments · May be fixed by #324
Closed

how to upgrade an http server to websockets? #308

dckc opened this issue Dec 31, 2019 · 3 comments · May be fixed by #324

Comments

@dckc
Copy link
Contributor

dckc commented Dec 31, 2019

The websocket server seems to always create its own listener socket. I'm trying to support an application (Agoric ag-solo, web.js) that initially uses its socket for ordinary GET requests for index.html and such before UPGRADEing to websockets. The popular ws package supports a noServer mode where an http handler can pass its socket when an UPGRDADE request comes in.

Any suggestions on how to do this?

My guess is I should make a revised websockets.js module.

@dckc
Copy link
Contributor Author

dckc commented Jan 2, 2020

I think I figured out how to extract the websockets Server handshake code into my http server and then just use your websockets Client code after the handshake.

It did require one tweak to your http module:

dckc@0efb618

Stay tuned for a PR with that change against master / public. (meanwhile, it went into #305 too).

FWIW, my client code that mostly works (though I need to support computing http responses asynchronously somehow; more on that separately, if I can't figure it out soon...):

https://github.com/dckc/agoric-sdk/blob/e7b49bcce7517a871057b05d9828a46324202057/packages/cosmic-swingset/lib/xs-node-api/http.js
https://github.com/dckc/agoric-sdk/blob/e7b49bcce7517a871057b05d9828a46324202057/packages/cosmic-swingset/lib/xs-npm/ws.js

@dckc
Copy link
Contributor Author

dckc commented Jan 2, 2020

p.s. Now I'm getting: main.js:30 WebSocket connection to 'ws://localhost:8000/' failed: A server must not mask any frames that it sends to the client.

Maybe there's a quick fix for that...

@dckc
Copy link
Contributor Author

dckc commented Jan 19, 2020

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 a pull request may close this issue.

1 participant