GithubHelp home page GithubHelp logo

gutcp's Introduction

guTcpSocket

简陋的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

初始化操作

初始化操作
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})

gutcp's People

Contributors

shenpan233 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.