client

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: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Destroy

func Destroy(hd Handle)

Types

type Handle

type Handle interface {
	Send(data map[string]interface{}) error
	Run() error
	Close()
}

func NewTcp

func NewTcp(opts *Options) Handle

func NewUdp

func NewUdp(opts *Options) Handle

type OnConnectHandler

type OnConnectHandler func(Handle)

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

type OnDataHandler

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

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

type OnDisconnectHandler

type OnDisconnectHandler func(Handle, error)

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

type OnReconnectHandler

type OnReconnectHandler func(Handle)

OnReconnectHandler sets the function to be called when the client is reconnected.

type Options

type Options struct {
	Address              string        `json:"address"`
	KeepAlive            time.Duration `json:"keepalive"`
	AuthenticationEnable bool          `json:"authenticationEnable"`
	AuthenticationKey    string        `json:"authenticationKey"`
	AutoReconnect        bool          `json:"autoReconnect"`
	ReconnectInterval    time.Duration `json:"reconnectInterval"`
	OnConnect            OnConnectHandler
	OnDisconnect         OnDisconnectHandler
	OnData               OnDataHandler
	OnReconnecting       OnReconnectHandler
}

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) SetAuthenticationKey

func (o *Options) SetAuthenticationKey(authenticationKey string) *Options

SetAuthenticationKey sets the key to be used when the client connected and for the first time send data.

func (*Options) SetAutoReconnect

func (o *Options) SetAutoReconnect(autoReconnect bool) *Options

SetAutoReconnect sets the function to be called when the client is reconnected.

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.

func (*Options) SetOnReconnectHandler

func (o *Options) SetOnReconnectHandler(onReconnect OnReconnectHandler) *Options

SetOnReconnectHandler sets the function to be called when the client is reconnected.

func (*Options) SetReconnectInterval

func (o *Options) SetReconnectInterval(interval time.Duration) *Options

SetReconnectInterval sets the interval of reconnection.

Jump to

Keyboard shortcuts

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