-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Question: Any way to safely get a ReadWriteCloser compatible with x/net/websocket? #282
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
Comments
The x/net/websocket package implements the net.Conn interface using messages. You can do the same. Here's an untested sketch on how to do this. It's not very complicated.
|
@garyburd , thank you so for the quick sketch. I expected it to be more complex. This is very nice. Switched out my implementations, and works perfectly so far. Closing this. But, just out of curiosity, any specific reason, why this can't be a part of websockets itself? |
The io.Reader and io.Writer interfaces are standard for byte streams. A websocket connection is a stream of messages, not bytes. |
Ok, makes sense. Thanks.
…Sent from my Android
On Sep 7, 2017 23:25, "Gary Burd" ***@***.***> wrote:
The io.Reader and io.Writer interfaces are standard for byte streams. A
websocket connection is a stream of messages, not bytes.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#282 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAiJMcX8QL5e3ALxYPsDJVSF-CUjiJcfks5sgC2DgaJpZM4PPVGY>
.
|
I'm trying to port https://github.com/rsms/gotalk to use gorilla websockets instead of x/net/websocket. However, it uses a common underlying handler for both the raw TCP stream, and websockets stream. The websockets one uses /x/net/websocket where it upgrades the connection, and the passes it on to the raw TCP handler, that handles things from there.
To be able to do this, x/net/websocket is pretty trivial. All it does is exposes the Conn after the upgrade that can be sent as a ReadWriteCloser. I'm wondering if it's possible to achieve this using Gorilla websockets, while still retaining the higher level features like compression that gorilla socket provides. From what little I looked under the hood, it only seems to have the raw underlying connection
conn
which cannot be passed since it will include the websocket framing, and reader and writer which are exposed throughNextReader
andNextWriter
which can change. Any way to do this without writing a complicated abstraction layer on top of NextReader/NextWriter?The text was updated successfully, but these errors were encountered: