| 18 | ) |
| 19 | |
| 20 | type Client struct { |
| 21 | sync.WaitGroup |
| 22 | sync.Mutex |
| 23 | started bool |
| 24 | ctx context.Context |
| 25 | cancel context.CancelFunc |
| 26 | // Client Name 客户端的名称 |
| 27 | Name string |
| 28 | // IP of the target server to connect 目标连接服务器的IP |
| 29 | Ip string |
| 30 | // Port of the target server to connect 目标连接服务器的端口 |
| 31 | Port int |
| 32 | Url *url.URL // 扩展,连接时带上其他参数 |
| 33 | // Custom headers for WebSocket connection WebSocket连接的自定义头信息 |
| 34 | WsHeader http.Header |
| 35 | // Client version tcp,websocket,客户端版本 tcp,websocket |
| 36 | version string |
| 37 | // Connection instance 连接实例 |
| 38 | conn ziface.IConnection |
| 39 | // Connection instance 连接实例的锁,保证可见性 |
| 40 | connMux sync.Mutex |
| 41 | // Hook function called on connection start 该client的连接创建时Hook函数 |
| 42 | onConnStart func(conn ziface.IConnection) |
| 43 | // Hook function called on connection stop 该client的连接断开时的Hook函数 |
| 44 | onConnStop func(conn ziface.IConnection) |
| 45 | // Data packet packer 数据报文封包方式 |
| 46 | packet ziface.IDataPack |
| 47 | // Asynchronous channel for capturing connection close status 异步捕获连接关闭状态 |
| 48 | // exitChan chan struct{} |
| 49 | // Message management module 消息管理模块 |
| 50 | msgHandler ziface.IMsgHandle |
| 51 | // Disassembly and assembly decoder for resolving sticky and broken packages |
| 52 | //断粘包解码器 |
| 53 | decoder ziface.IDecoder |
| 54 | // Heartbeat checker 心跳检测器 |
| 55 | hc ziface.IHeartbeatChecker |
| 56 | // Use TLS 使用TLS |
| 57 | useTLS bool |
| 58 | // For websocket connections |
| 59 | dialer *websocket.Dialer |
| 60 | // Error channel |
| 61 | errChan chan error |
| 62 | } |
| 63 | |
| 64 | func NewClient(ip string, port int, opts ...ClientOption) ziface.IClient { |
| 65 |
nothing calls this directly
no outgoing calls
no test coverage detected