简陋的tcp组件
本零件所有收发数据操作都会进行编码处理,即Len+4+Data
编码处理->len[数据长度+包头长度]+要发送的数据
举个例子↓
如果我要发送的数据是16个00(00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00)
实际对方收到的封包为 00 00 00 14 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
这里的00 00 00 14 转10进制为20,刚好是16字节+4(包头长度)
server := new(Socket.GuTcpServer)//手动创建定义就好QWQ
//绑定数据接收回调程序
// uid 用户标识id
// bin 已进行粘包处理的剩余数据
server.BindingEvent(func(userId uint64, bin []byte) {
//客户发送的数据都要在这里进行处理
})
server.Creat(8848) //开放8848端口用于客户端连接
//创建成功后此处会阻塞,如果失败就会在控制台打印失败的消息
fmt.Println("QWQ阻塞了打印不出来")
//发送16个00给用户id是1的客户
server.Send(1, []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0})
//将数据发送给所有已连接的客户端
server.GroupSend([]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0})