gopherjs / websocket

websocket provides high- and low-level bindings for the browser's WebSocket API.
BSD 3-Clause "New" or "Revised" License
111 stars 25 forks source link

net.Conn is the wrong API for WebSockets #29

Closed nhooyr closed 4 years ago

nhooyr commented 5 years ago

golang.org/x/net/websockets has a similar API that is considered problematic.

See https://github.com/golang/go/issues/18152#issuecomment-264321561

the deeper problem with x/net/websocket is that it has the wrong API. It puts an io.Reader/Writer interface on top of what is fundamentally a message-based protocol.

nhooyr commented 5 years ago

Not sure what can be done about it now other than making a v2.

theclapp commented 5 years ago

If someone wants to use a message-based API, there's always gopherjs/websocket/websocketjs.

Having a net.Conn (probably) makes it easier for GopherJS users to write isomorphic Go (code that's the same for the browser and the server). And that aside, having an official net.Conn implementation means that people that want one don't have to write their own on top of gopherjs/websocket/websocketjs, it's just there.

nhooyr commented 5 years ago

If someone wants to use a message-based API, there's always gopherjs/websocket/websocketjs.

Yes but it is callback based which makes it frustrating to use.

Having a net.Conn (probably) makes it easier for GopherJS users to write isomorphic Go (code that's the same for the browser and the server). And that aside, having an official net.Conn implementation means that people that want one don't have to write their own on top of gopherjs/websocket/websocketjs, it's just there.

I agree isomorphic code is nice so I modified my WebSocket library to support WASM.

See https://github.com/nhooyr/websocket/pull/142

Once Go 1.13 is supported by GopherJS, I think it's best to recommend my library instead which provides a nicer API for when you don't need a net.Conn but also provides a net.Conn wrapper, all with the exact same API for targeting WASM or any other "normal" Go target.

nhooyr commented 4 years ago

Going to close as it has been a while and I'm not sure if this is relevant anymore.