Documentation ¶
Index ¶
- Constants
- func EncodeDataHdr(hdr DataHdr) ([]byte, error)
- func ReadData(conn net.Conn, datalen int) ([]byte, error)
- func ReadDataHdr(conn net.Conn) (data []byte, err error)
- func WriteData(conn net.Conn, data []byte, chanid uint16) (bool, error)
- type AcceptCbFunc
- type CloseCbFunc
- type DataHdr
- type ReadCbFunc
- type TcpClient
- type TcpServer
- func (ts *TcpServer) Close(conn net.Conn)
- func (ts *TcpServer) Join(conn net.Conn)
- func (ts *TcpServer) KickConn(conn net.Conn)
- func (ts *TcpServer) Listen(addr string) bool
- func (ts *TcpServer) Loop()
- func (ts *TcpServer) ReadConn(conn net.Conn)
- func (ts *TcpServer) Send(conn net.Conn, data []byte, ChanID uint16) (bool, error)
- func (ts *TcpServer) Stop()
Constants ¶
const ( //PackMaxSize 定义单个通信包最大字节数 PackMaxSize = uint32(6553500) //定义包头flag PackHdrFlag = uint16(0xAABB) )
Variables ¶
This section is empty.
Functions ¶
func EncodeDataHdr ¶
EncodeDataHdr 将数据包头信息序列化为网络数据 +++++++++++++++++++++++++++++++++++++---------------------------- | 2B flag | 2B chanid |4B data length | (n) data | +++++++++++++++++++++++++++++++++++++----------------------------
Types ¶
type AcceptCbFunc ¶
type CloseCbFunc ¶
type DataHdr ¶
DataHdr 数据包头定义
func DecodeDataHdr ¶
DecodeDataHdr 将网络数据反序列化为数据包头 +++++++++++++++++++++++++++++++++++++---------------------------- | 2B flag | 2B chanid |4B data length | (n) data | +++++++++++++++++++++++++++++++++++++----------------------------
type TcpClient ¶
type TcpClient struct {
// contains filtered or unexported fields
}
TcpClient TCP客户端结构体定义
func (*TcpClient) Connect ¶
Connect : 连接函数,目标服务器地址类型"192.168.1.105:9981" args... 第1个参数是bool类型,是否将地址解析为TCP6格式(默认false)
type TcpServer ¶
type TcpServer struct { OnAccept AcceptCbFunc //收到连接通知回调 OnRead ReadCbFunc //消息接收完毕回调 OnClose CloseCbFunc //连接断开回调 // contains filtered or unexported fields }
TcpServer TCP服务对象
func CreateTcpServer ¶
func CreateTcpServer(cbAccept AcceptCbFunc, cbClose CloseCbFunc, cbRead ReadCbFunc) (ts *TcpServer)
CreateTcpServer 创建TCP服务 return ts TCP服务对象
func (*TcpServer) Listen ¶
Listen 监听并接收客户端连接 addr参数 1、非加密模式服务监听URL "tcp://192.168.1.105:8899"监听指定IP端口或"tcp://:8899"监听本机所有IP端口
2、加密模式服务监听URL "tls://192.168.1.105:8899" 监听指定IP端口或"tls://:8899"监听本机所有IP端口
return conn接收的连接,err 错误信息