代码拉取完成,页面将自动刷新
package server
import (
"gitee.com/siliworks/common-package/collector/module/define"
"gitee.com/micro-tools/wf/net/gtcp"
"gitee.com/micro-tools/wf/net/gudp"
"gitee.com/micro-tools/wf/os/gtime"
"net"
"time"
)
type Client struct {
Address string `json:"address"`
HeartBeatAt *gtime.Time `json:"heartBeatAt"`
ConnectAt *gtime.Time `json:"connectAt"`
Conn *gtcp.Conn
ReceiveCount int64 `json:"receiveData"`
SendCount int64 `json:"sendData"`
}
type UdpClient struct {
Address string `json:"address"`
HeartBeatAt *gtime.Time `json:"heartBeatAt"`
ConnectAt *gtime.Time `json:"connectAt"`
Conn *gudp.Conn
ReceiveCount int64 `json:"receiveData"`
SendCount int64 `json:"sendData"`
}
// Handle 接口
type Handle interface {
Send(key string, data []byte) error
GetClient(key string) *Client
RemoveClientFromBlacklist(key string) error
CloseClient(key string) error
CloseAllClient() error
ClientList() []*Client
Run() error
}
// OnConnectHandler 客户端连接成功后的回调函数
type OnConnectHandler func(Handle, *net.Conn)
// OnDisconnectHandler 客户端断开后的回调函数
type OnDisconnectHandler func(Handle, error)
// OnDataHandler 客户端收到数据后的回调函数
type OnDataHandler func(Handle, map[string]interface{}, string)
// OnAuthenticationHandler 认证回调函数
type OnAuthenticationHandler func(Handle, define.AgreementData) bool
type Options struct {
Address string `json:"address"`
KeepAlive time.Duration `json:"keepalive"`
AuthenticationEnable bool `json:"authenticationEnable"`
ClientConnectCap int `json:"clientConnectCap"`
ClientSameIPCap int `json:"clientSameIPCap"`
BlacklistDuration int64 `json:"blacklistDuration"`
AuthenticationFailedCap int `json:"authenticationFailedCap"`
OnConnect OnConnectHandler
OnDisconnect OnDisconnectHandler
OnData OnDataHandler
OnAuthentication OnAuthenticationHandler
}
// SetAddress sets the address to be used by the client to connect.
func (o *Options) SetAddress(address string) *Options {
o.Address = address
return o
}
// SetAuthenticationEnable sets the function to be called when the client connected and for the first time receives data.
func (o *Options) SetAuthenticationEnable(authenticationEnable bool) *Options {
o.AuthenticationEnable = authenticationEnable
return o
}
// SetClientConnectCap sets the maximum number of concurrent connections.
func (o *Options) SetClientConnectCap(cap int) *Options {
o.ClientConnectCap = cap
return o
}
// SetClientSameIPCap sets the maximum number of concurrent connections from the same IP.
func (o *Options) SetClientSameIPCap(cap int) *Options {
o.ClientSameIPCap = cap
return o
}
// SetBlacklistDuration sets the duration of the blacklist.
func (o *Options) SetBlacklistDuration(duration int64) *Options {
o.BlacklistDuration = duration
return o
}
// SetAuthenticationFailedCap sets the maximum number of authentication failures.
func (o *Options) SetAuthenticationFailedCap(cap int) *Options {
o.AuthenticationFailedCap = cap
return o
}
// SetOnConnectHandler sets the function to be called when the client is connected. Both
func (o *Options) SetOnConnectHandler(onConn OnConnectHandler) *Options {
o.OnConnect = onConn
return o
}
// SetOnDisconnectHandler sets the function to be called when the client is disconnected.
func (o *Options) SetOnDisconnectHandler(onLost OnDisconnectHandler) *Options {
o.OnDisconnect = onLost
return o
}
// SetOnDataHandler sets the function to be called when the client receives data.
func (o *Options) SetOnDataHandler(onData OnDataHandler) *Options {
o.OnData = onData
return o
}
// SetOnAuthenticationHandler sets the function to be called when the client receives data.
func (o *Options) SetOnAuthenticationHandler(onAuth OnAuthenticationHandler) *Options {
o.OnAuthentication = onAuth
return o
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。