Skip to content

net.Conn is the wrong API for WebSockets #29

Closed
@nhooyr

Description

@nhooyr
Contributor

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

See golang/go#18152 (comment)

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.

Activity

nhooyr

nhooyr commented on Sep 20, 2019

@nhooyr
ContributorAuthor

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

theclapp

theclapp commented on Sep 21, 2019

@theclapp

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

nhooyr commented on Sep 22, 2019

@nhooyr
ContributorAuthor

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 coder/websocket#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

nhooyr commented on Nov 22, 2019

@nhooyr
ContributorAuthor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @theclapp@nhooyr

        Issue actions

          net.Conn is the wrong API for WebSockets · Issue #29 · gopherjs/websocket