tcp_utils

package
v1.1.13 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListenAndServe

func ListenAndServe(addr string, handler func(*TCPConn)) error

ListenAndServe 监听TCP连接

Types

type TCPConn

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

TCPConn TCP连接封装

func Dial

func Dial(addr string, timeout time.Duration) (*TCPConn, error)

Dial 连接到TCP服务器

func NewTCPConn

func NewTCPConn(conn net.Conn) *TCPConn

NewTCPConn 创建新的TCP连接

func (*TCPConn) AsyncRead

func (t *TCPConn) AsyncRead(handleFunc func([]byte, error))

AsyncRead 异步读取消息

func (*TCPConn) AsyncWrite

func (t *TCPConn) AsyncWrite(data []byte, callback func(error))

AsyncWrite 异步写入消息

func (*TCPConn) Close

func (t *TCPConn) Close()

Close 安全关闭连接

func (*TCPConn) Done

func (t *TCPConn) Done() <-chan struct{}

Done 获取关闭信号通道

func (*TCPConn) IsClosed

func (t *TCPConn) IsClosed() bool

IsClosed 检查连接是否已关闭

func (*TCPConn) LocalAddr

func (t *TCPConn) LocalAddr() string

LocalAddr 获取本地地址

func (*TCPConn) OnMessage

func (t *TCPConn) OnMessage(handleFunc func([]byte)) error

OnMessage 持续处理消息

func (*TCPConn) Read

func (t *TCPConn) Read() ([]byte, error)

Read 从连接读取数据

func (*TCPConn) RemoteAddr

func (t *TCPConn) RemoteAddr() string

RemoteAddr 获取对端地址

func (*TCPConn) SetKeepAlive

func (t *TCPConn) SetKeepAlive(keepalive bool) error

SetKeepAlive 设置TCP KeepAlive

func (*TCPConn) SetKeepAlivePeriod

func (t *TCPConn) SetKeepAlivePeriod(d time.Duration) error

SetKeepAlivePeriod 设置KeepAlive间隔

func (*TCPConn) SetLogger

func (t *TCPConn) SetLogger(logger *log.Logger)

SetLogger 设置自定义日志记录器

func (*TCPConn) SetTimeouts

func (t *TCPConn) SetTimeouts(readTimeout, writeTimeout time.Duration)

SetTimeouts 设置读写超时

func (*TCPConn) StartHeartbeat

func (t *TCPConn) StartHeartbeat(interval time.Duration, heartbeatMsg []byte)

StartHeartbeat 启动心跳机制

func (*TCPConn) StopHeartbeat

func (t *TCPConn) StopHeartbeat()

StopHeartbeat 停止心跳机制

func (*TCPConn) Write

func (t *TCPConn) Write(data []byte) error

Write 向连接写入数据

Jump to

Keyboard shortcuts

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