tcp

package
v0.1.1-beta.2 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2025 License: Apache-2.0 Imports: 7 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 {
	// contains filtered or unexported fields
}

Client 表示一个 TCP 客户端

func NewClient

func NewClient(cfg Config) *Client

NewClient 创建新的客户端

func (*Client) Close

func (c *Client) Close()

Close 优雅关闭客户端

func (*Client) Receive

func (c *Client) Receive() ([]byte, error)

Receive 阻塞接收消息

func (*Client) Send

func (c *Client) Send(data []byte) error

Send 异步发送消息

func (*Client) Start

func (c *Client) Start()

Start 启动客户端,进入自动重连模式

type Config

type Config struct {
	Address        string
	Port           int32
	ConnTimeout    time.Duration
	ReadTimeout    time.Duration
	WriteTimeout   time.Duration
	ReconnectDelay time.Duration
	KeepAlive      bool
}

Config 配置 TCP 客户端

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager 管理多个客户端

func NewManager

func NewManager() *Manager

NewManager 创建管理器

func (*Manager) AddClient

func (m *Manager) AddClient(name string, client *Client)

AddClient 添加客户端

func (*Manager) CloseAll

func (m *Manager) CloseAll()

CloseAll 关闭所有客户端

func (*Manager) GetClient

func (m *Manager) GetClient(name string) (*Client, bool)

GetClient 获取客户端

func (*Manager) RemoveClient

func (m *Manager) RemoveClient(name string)

RemoveClient 删除并关闭客户端

Jump to

Keyboard shortcuts

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