iris icon indicating copy to clipboard operation
iris copied to clipboard

with https://github.com/googollee/go-socket.io

Open zkcrescent opened this issue 9 years ago • 3 comments

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

zkcrescent avatar Aug 15 '17 13:08 zkcrescent

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.

hiveminded avatar Aug 15 '17 18:08 hiveminded

@zkcrescent please answer to @hiveminded , did that helped you?

kataras avatar Aug 18 '17 14:08 kataras

i run the _examples/websocket/third-party-socketio/main.go ,but the client always get 301 error code @hiveminded

TaleAi avatar Aug 22 '17 03:08 TaleAi