IpConnAddr

This commit is contained in:
ideaa
2025-02-11 15:06:32 +08:00
parent 9eaad77d4c
commit 503110fc1a
2 changed files with 5 additions and 3 deletions

View File

@@ -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 {

View File

@@ -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,