package
0.1.3
Repository: https://github.com/chenjunpc2008/go-tcp.git
Documentation: pkg.go.dev

# README

cchantcpclient

tcp cleint frame

  • notice client events via event callback handler.
  • could define your own package pack/unpack protocol.
  • each client with have it's own read and write goroutine, write messages will store in the send queue(use channel) before acctually write into system tcp send buffer.
  • client will handler client connection session, upper layer will only have to process business session layer's management.

tcp client架构

  • 通过事件回调handler向外反馈client事件
  • 自定义消息的拆解包协议
  • 每个客户端有独立的读写go协程,待发送消息会先存入发送队列(使用channel),再写入系统tcp发送缓冲区
  • 客户端将管理client连接,上层应用仅需按协议处理session层的内容
accepting connection:
+------------+    +------------+    +----------------+
|            |    |            |    |                |
| tcp client |--->| establish  |--->| set client     |
|            |    | connection |    |   connection  |
|            |    |            |    |   management   |
+------------+    +------------+    +----------------+
                                            |
                                            |
+------------+    +-------------------+     |
|            |    |                   |     |
| your own   |<---| OnNewConnection() | <---+
|  process   |    | callback          |  
|            |    |                   | 
+------------+    +-------------------+

in client life time:
read tcp datas
+------------+    +-----------------------+    +-----------------+
| read       |    | unpack packet payload |    | OnReceiveData() |
| connection |--->| use your own protocol |--->| callback        |
+------------+    +-----------------------+    +-----------------+

send tcp datas
+------------+    +-----------+    +------------+
| your own   |    | server    |    | client's   |
| app send   |--->| send func |--->| send queue |
+------------+    +-----------+    +------------+
                                            |
                                            |
   +--------------+     +--------------+    |
   | client's send |    | pack packet  |    |
   | loop write    |<---| use your own |<---+
   | []byte to sys |    |  protocol    | 
   | tcp send buff |    +--------------+
   +---------------+