我使用此代码但无法获取 IP 地址。我如何获取用户IP/端口地址?我可以使用 Id() 获取套接字 id。下面的代码运行良好,但我找不到如何为如此变量使用更多选项和函数。package mainimport ( "log" "net/http" "github.com/googollee/go-socket.io")func main() { server, err := socketio.NewServer(nil) if err != nil { log.Fatal(err) } log.Println("server", server) server.On("connection", func(so socketio.Socket) { log.Println("so------->> " ,so ) log.Println("id------->> " , so.Id() ) log.Println("on connection") 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) }) http.Handle("/socket.io/", server) log.Println("Serving at localhost:5555...") log.Fatal(http.ListenAndServe(":5555", nil))}
- 1 回答
- 0 关注
- 105 浏览
添加回答
举报
0/150
提交
取消