|
|
@@ -35,10 +35,25 @@ type Connect interface {
|
|
|
WriteResponse(id uint16, state uint8, data []byte) error
|
|
|
WritePing(id uint16) error
|
|
|
ReadMessage(deadline int) (msgType MsgType, id uint16, cmd string, state uint8, data []byte, err error)
|
|
|
- RemoteAddr() net.Addr
|
|
|
- LocalAddr() net.Addr
|
|
|
+ RemoteIP() net.IP
|
|
|
+ LocalIP() net.IP
|
|
|
Close() error
|
|
|
}
|
|
|
|
|
|
// 服务请求连接
|
|
|
type ServerConnectFunc func(conn Connect)
|
|
|
+
|
|
|
+// addrToIP attempts to extract a net.IP from a net.Addr
|
|
|
+func AddrToIP(addr net.Addr) net.IP {
|
|
|
+ switch v := addr.(type) {
|
|
|
+ case *net.TCPAddr:
|
|
|
+ return v.IP
|
|
|
+ case *net.UDPAddr:
|
|
|
+ return v.IP
|
|
|
+ case *net.IPAddr:
|
|
|
+ return v.IP
|
|
|
+ default:
|
|
|
+ // Handle other potential net.Addr implementations or return nil
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+}
|