Any example ?
ZinedineR opened this issue · 3 comments
I'm trying to migrate from https://github.com/googollee/go-socket.io. But I'm currently using gin-gonic as http handler, and it would help a lot if there's base example how to use event and namespace, because in the readmemd it only use (...any) as parameter.
Hello, regarding the problem you described, here is what may be helpful:
- There are currently some comment snippets in the golang source code containing examples. Of course, you can also view the socket.io documentation directly: https://socket.io/docs/v4/server-initialization/. There is almost no big difference between golang syntax and nodejs.
- You can clone the repository https://github.com/zishang520/socket.io-test. The
socket.io.go
file may be helpful to you. You can also execute make socket.io to run the program and then visithttp://127.0.0.1:9999/index.html
.
Finally, thank you for your choice. If you have any questions, please feel free to ask.
Oh hello Zishang520, I have successfully created gin server with the socket.io package you created.
type HttpServe struct {
router *gin.Engine
serverio *socket.Server
}
func (h *HttpServe) setupSocketio() {
h.router.GET("/socket.io/*any", gin.WrapH(h.serverio.ServeHandler(nil)))
h.router.POST("/socket.io/*any", gin.WrapH(h.serverio.ServeHandler(nil)))
h.router.StaticFS("/public", http.Dir("./app/api/asset"))
}
the server worked well, but since this package is still new for me, thank you for creating this, since we need socket.io package for golang that support 4.x.
One more question, I noticed in the socket.io-test, your html uses this for js script
<script type="text/javascript" src="http://127.0.0.1:9999/socket.io/socket.io.min.js"></script>Mine is using the official socket io js package for 4.6.0, and it still working. Why in the example use local js?
@ZinedineR Due to network reasons, an offline js library is used. You can also use the js library provided by cdn. You mainly need to debug the js files integrated in socket.io for golang.