kataras / go-websocket

:speaker: Deprecated. Use https://github.com/kataras/neffos instead
MIT License
59 stars 16 forks source link

Secure websocket (wss) #26

Closed bluedaniel closed 7 years ago

bluedaniel commented 7 years ago

I'm currently using your framework using ListenTLS and then opening up a few websockets. Everything works perfectly if I don't use TLS but I cannot figure out how to enable wss:// over the original ws:// protocol.

api := iris.New()

ws := iris.NewWebsocketServer(api)
ws.Config = iris.WebsocketConfiguration{Endpoint: "/ws"}
ws.OnConnection(func(ctx iris.WebsocketConnection) {
   ...
})

api.ListenTLS(":443", "/tls/certificate.crt", "/tls/private.key")

Is there anything more I have to do to enable the protocol?

Thanks for the excellent framework 👍

ghost commented 7 years ago

Hello @bluedaniel thanks for your nice words, I do my bests.

First I have to note some things, you don't have to use this lib if you don't want, Iris is compatible with socket.io too, see: https://github.com/kataras/go-websocket/issues/25#issuecomment-276942582 ( I use the kataras/go-websocket for my apps because it's fast and simple)

About secure ws, the question has been already posted here: https://github.com/kataras/iris/issues/291 and the user verified that wss:// is used when the server is running over TLS.

Try this too:


api := iris.New()

api.Config.Websocket.Endpoint ="/ws"
api.OnConnection(func(ctx iris.WebsocketConnection) {
   ...
})

api.ListenTLS(":443", "/tls/certificate.crt", "/tls/private.key") 
// if ListenTLS doesn't works try a second example with `api.ListenLETSENCRYPT(":443")` 
// and tell me what worked for you and what didn't work

and tell me the results, otherwise we will need more information to debug that

bluedaniel commented 7 years ago

Hey @kataras, so sorry for bothering you as I've found the issue and it's nothing to do with the framework.

I've got the app running on AWS Elastic Beanstalk and their load balancer doesnt connect to any websockets if the protocol listener is HTTP, it must be TCP.

Thanks again for your best efforts and quick response to my issue.

ghost commented 7 years ago

You're welcome, for your issue you can use net.Listener to start an iris server too.

    // create our custom listener
    ln, err := net.Listen("tcp4", ":8080")
    if err != nil {
        panic(err)
    }

    // use of the custom listener
        api.Serve(ln)