diff --git a/ws/dispatcher.go b/ws/dispatcher.go index 58e2290..e2972d5 100644 --- a/ws/dispatcher.go +++ b/ws/dispatcher.go @@ -26,7 +26,7 @@ func Dispatcher(c *Client, request string) { } //请求频率限制5毫秒 - if t.Sub(c.LastRequestTime).Microseconds() <= 5 { + if t.Sub(c.LastRequestTime).Microseconds() <= 2 { c.SendRawMsg(-13, "sys.requestLimit", "Your requests are too frequent", nil) return } else { diff --git a/ws/server_handler_http.go b/ws/server_handler_http.go index 00df4cd..c5c786f 100644 --- a/ws/server_handler_http.go +++ b/ws/server_handler_http.go @@ -1,6 +1,7 @@ package ws import ( + "fmt" "net" "net/http" "time" @@ -31,6 +32,7 @@ func HttpHandler(w http.ResponseWriter, r *http.Request) { r.Header.Set("Sec-Websocket-Protocol", h.Protocol) } + ipAddr := ip.GetIPAddress(r) addr, ok := conn.RemoteAddr().(*net.TCPAddr) if !ok { logger.SugarLog.Errorf("获取IP地址错误") @@ -41,8 +43,8 @@ func HttpHandler(w http.ResponseWriter, r *http.Request) { Hub: Hub, Conn: conn, Send: make(chan []byte, 32), - IpAddress: ip.GetIPAddress(r), - IpConnAddr: addr.String(), + IpAddress: ipAddr, + IpConnAddr: fmt.Sprintf("%s:%d", ipAddr, addr.Port), ConnectionTime: time.Now(), HttpRequest: r, HttpWriter: w,