呼啦一阵风
我假设您想使用 Socket.IO 服务器库的 Go 实现而不是标准的 Node.js 实现。如果是这样,您可以尝试googollee/go-socket.io 项目。这是项目页面中的示例:package mainimport ( "log" "net/http" "github.com/googollee/go-socket.io")func main() { 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)) server.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) }) http.Handle("/socket.io/", server) http.Handle("/", http.FileServer(http.Dir("./asset"))) log.Println("Serving at localhost:5000...") log.Fatal(http.ListenAndServe(":5000", nil))}