server

package
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2023 License: MulanPSL-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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 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
}

Handle 接口

func NewTcp

func NewTcp(opts *Options) Handle

func NewUdp

func NewUdp(opts *Options) Handle

type OnAuthenticationHandler

type OnAuthenticationHandler func(Handle, define.AgreementData) bool

OnAuthenticationHandler 认证回调函数

type OnConnectHandler

type OnConnectHandler func(Handle, *net.Conn)

OnConnectHandler 客户端连接成功后的回调函数

type OnDataHandler

type OnDataHandler func(Handle, map[string]interface{}, string)

OnDataHandler 客户端收到数据后的回调函数

type OnDisconnectHandler

type OnDisconnectHandler func(Handle, error)

OnDisconnectHandler 客户端断开后的回调函数

type Options

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
}

func (*Options) SetAddress

func (o *Options) SetAddress(address string) *Options

SetAddress sets the address to be used by the client to connect.

func (*Options) SetAuthenticationEnable

func (o *Options) SetAuthenticationEnable(authenticationEnable bool) *Options

SetAuthenticationEnable sets the function to be called when the client connected and for the first time receives data.

func (*Options) SetAuthenticationFailedCap

func (o *Options) SetAuthenticationFailedCap(cap int) *Options

SetAuthenticationFailedCap sets the maximum number of authentication failures.

func (*Options) SetBlacklistDuration

func (o *Options) SetBlacklistDuration(duration int64) *Options

SetBlacklistDuration sets the duration of the blacklist.

func (*Options) SetClientConnectCap

func (o *Options) SetClientConnectCap(cap int) *Options

SetClientConnectCap sets the maximum number of concurrent connections.

func (*Options) SetClientSameIPCap

func (o *Options) SetClientSameIPCap(cap int) *Options

SetClientSameIPCap sets the maximum number of concurrent connections from the same IP.

func (*Options) SetOnAuthenticationHandler

func (o *Options) SetOnAuthenticationHandler(onAuth OnAuthenticationHandler) *Options

SetOnAuthenticationHandler sets the function to be called when the client receives data.

func (*Options) SetOnConnectHandler

func (o *Options) SetOnConnectHandler(onConn OnConnectHandler) *Options

SetOnConnectHandler sets the function to be called when the client is connected. Both

func (*Options) SetOnDataHandler

func (o *Options) SetOnDataHandler(onData OnDataHandler) *Options

SetOnDataHandler sets the function to be called when the client receives data.

func (*Options) SetOnDisconnectHandler

func (o *Options) SetOnDisconnectHandler(onLost OnDisconnectHandler) *Options

SetOnDisconnectHandler sets the function to be called when the client is disconnected.

type UdpClient

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"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL