Comments (3)
@xhaoxiong 我们对unpack的设计和理解应该是从一个tcp原始数据 -> 我们可以用的最基本的数据包,将业务代码和原始报文处理分离。在里面就需要人们根据自己的需求去实现对应的unpack方法。换而言之,netty的各种decoder方法我们都可以基于我们的 unpack 去实现对应功能。
我这里举个例子,如果我们是按长度取数的话,在unpack里就可以 if buffer.virtrualLength() > 100
去判断是否有足够的数据,再决定返回内容继续处理还是nil来等待下次数据到来。对于其他的decoder方法都可以类比实现(有机会我们会在库里提供对应实现方便使用)。
当然还有很多不完善和有问题的的地方,如果有更好的意见或者建议请提给我们。
from gev.
使用protobuf 序列化 , 通过多线程发报文的情况下,确实有粘报文体,代码如下:
top, tail := buffer.PeekAll()
data := append(top, tail...)
log.Printf("request Host:[%s] msg:%x", c.PeerAddr(), data)
var communication protobuf.Communication
if e := proto.Unmarshal(data, &communication); e == nil {
buffer.RetrieveAll()
//逻辑处理
} else {
log.Printf("Unmarshal error %v", e)
}
communication Unmarshal error:proto: protobuf.Communication: illegal tag 0 (wire type 1)
from gev.
@itlabers 对于网络处理,一定要有方式去把“数据包”正确完整得取出来。对于你这种推荐在包头用2字节确认后续包长度,可以看ws对于数据包得处理。
from gev.
Related Issues (20)
- 这里为什么是一个循环啊??? HOT 2
- How to use with gin HOT 1
- 事件处理顺序如何排序,这里的排序有什么讲究? HOT 4
- Are the writes to socket blocking or non-blocking? HOT 3
- 这里的循环是不是换成if也行 HOT 2
- 请教一个问题,实在没看懂。 HOT 4
- 关闭连接时,为什么不直接关闭连接,而是将【关闭连接】这个任务放到异步队列里面等待执行? HOT 3
- 请问一下该库能管理大量客户端连接么? HOT 1
- 对于gev的一些疑问 HOT 1
- 控制EpollWait的msec优势在哪?
- EpollWait循环中wakeHandlerRead()是不是处理早了 HOT 1
- 建议加入UDP协议 HOT 1
- 百兆数据传输效率 HOT 2
- Question: is it possible to use your module as a websocket client? HOT 1
- OnConnect 里使用 c.set 的请教! HOT 1
- 能不能加一个sproto支持啊?
- 是否应该加入高水位回调来避免客户端不收数据
- windows 下cpu、内存占用问题
- 不会触发OnClose
- cpu跑到400%, 目前只有2个连接,抓包只有60s定时的心跳
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 gev.