iris
iris copied to clipboard
with https://github.com/googollee/go-socket.io
i have an issue with https://github.com/googollee/go-socket.io at the current version of iris.
my main function:
func main(){
app := iris.New()
server, err := socketio.NewServer(nil)
if err != nil {
log.Fatal(err)
}
server.On("connection", func(so socketio.Socket) {
log.Println("on connection")
so.Join("chat")
so.On("chat message", func(msg string) {
log.Println("emit:", so.Emit("chat message", msg))
so.BroadcastTo("chat", "chat message", msg)
})
so.On("disconnection", func() {
log.Println("on disconnect")
})
})
server.On("error", func(so socketio.Socket, err error) {
log.Println("error:", err)
})
app.Any("/socket.io", iris.FromStd(server))
app.Run(iris.Addr(":8080"))
}
but the client always get 301 error code
please help me to fix it. THX
Thats because of the redirect, the socket.io library makes calls to the "/socket.io/", you can fix it by disabling the path correction but I would recommend do that instead:
app.Any("/socket.io/{p:path}", iris.FromStd(server))
This should do the job.
@zkcrescent please answer to @hiveminded , did that helped you?
i run the _examples/websocket/third-party-socketio/main.go ,but the client always get 301 error code @hiveminded