From 3cf90d5231d2a025fb68fd639551d4bfdb22fe11 Mon Sep 17 00:00:00 2001 From: yu Date: Thu, 16 Apr 2020 14:08:51 +0800 Subject: [PATCH] add websocket client ip --- broker/client.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/broker/client.go b/broker/client.go index 7d2d714..ce862c4 100644 --- a/broker/client.go +++ b/broker/client.go @@ -14,6 +14,7 @@ import ( "github.com/fhmq/hmq/broker/lib/sessions" "github.com/fhmq/hmq/broker/lib/topics" "github.com/fhmq/hmq/plugins/bridge" + "golang.org/x/net/websocket" "github.com/eclipse/paho.mqtt.golang/packets" "go.uber.org/zap" @@ -99,6 +100,9 @@ func (c *client) init() { c.info.remoteIP = "" if remoteNetwork != "websocket" { c.info.remoteIP, _, _ = net.SplitHostPort(remoteAddr.String()) + } else { + ws := c.conn.(*websocket.Conn) + c.info.remoteIP, _, _ = net.SplitHostPort(ws.Request().RemoteAddr) } c.ctx, c.cancelFunc = context.WithCancel(context.Background()) c.subMap = make(map[string]*subscription)