Comments (2)
如果有protobuf,或者 json这种上层数据协议需要承载,那么在zinx应用端完成解析就好了,handle里发送的序列化只是启动客户端和服务端传输标准。 如果需要发送protobuf,那么直接把protobuf放到data里就好了。
例如:
`
//protobuf
data := &pb.BroadCast{
Pid:p.Pid,
Tp:2,
Data:&pb.BroadCast_P{
&pb.Position{
X:p.X,
Y:p.Y,
Z:p.Z,
V:p.V,
},
},
}
for _, player := range players{
/* 发送消息,使用zinx的SendMsg*/
player.SendMsg(200, data)
}
`
`
/* handle 处理数据 */
type Api2Router struct {
fnet.BaseRouter
}
func (*Api2Router)Handle(request iface.IRequest){
msg := &pb.BroadCast{}
err := proto.Unmarshal(request.GetData(), msg)
if err != nil{
logger.Error(err)
request.GetConnection().Stop()
return
}
// ....
}
`
from zinx.
ok, 了解了
from zinx.
Related Issues (20)
- zinx这种情况是否需要加锁 HOT 1
- CPU百分百-不懂就问系列 HOT 3
- 消息ID HOT 1
- connection StartReader 处理数据,解码之后只有数据前8位,导致数据丢失 HOT 11
- 冰哥,最新更新消息丢给责任链这个源码,看不懂,能不能开个教程啊! HOT 4
- 连接id,只能固定系统自动生成吗? HOT 2
- [Bug]: 程序卡死 HOT 5
- Join the Zinx community (加入Zinx Issue讨论社区)
- 针对自定义的消息体实现IMessage,如何定义?
- 请教一个关于多server的问题 HOT 1
- 生产环境下的log HOT 1
- connection.go can't use c.cancel() HOT 1
- 2个问题 HOT 2
- 请教一个问题
- Support http interface HOT 1
- websocket 可以支持 TextMessage格式吗 HOT 1
- 责任链(chain)代码疑问
- v1.1.1运行mmo_game_client出现报错,求指教w HOT 1
- 头部内容固定,脏数据不能处理,一直阻塞到半包 HOT 3
- [feat]: 配置参数可以通过环境变量覆盖 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zinx.