Can anyone help setting up a server that also handles web-socket with gin? Preferably I would like to use github.com/googollee/go-socket.io
Thanks.
Comment From: nazwa
I don't have the code anymore but the way it worked was that you set up gin and socket.io as usual (https://github.com/googollee/go-socket.io#example) and then just map the socket handler to a gin handler
r.GET("/socket/", gin.WrapH(server))
That's it
Comment From: LicaSterian
Thank's. I didn't know the gin.WrapH
method part.
Comment From: c9s
gin.WrapH is not a type
Comment From: c9s
And gin doesn't work with github.com/googollee/go-socket.io
Tested: go-socket.io + HTTP / HTTPS works pretty fine
Here is the error message I got when integrating gin with go-socket.io
WebSocket connection to 'wss://localhost:9096/socket.io/?EIO=3&transport=websocket&sid=95lAIzu8kRVD-ZwzHEjn' failed: Error during WebSocket handshake: Unexpected response code: 403
Comment From: javierprovecho
@c9s check https://godoc.org/github.com/gin-gonic/gin#WrapF and https://godoc.org/github.com/gin-gonic/gin#WrapH
can you post an example code for that failure?
Comment From: doquangtan
Use can use this lib socket.io golang. It is socketio server version 4.x and it can using with client version 3.x, 4.x
import (
"github.com/gin-gonic/gin"
socketio "github.com/doquangtan/socket.io/v4"
)
func main() {
io := socketio.New()
io.OnConnection(func(socket *socketio.Socket) {
// ...
})
router := gin.Default()
router.GET("/socket.io/", gin.WrapH(io.HttpHandler()))
router.Run(":3300")
}