Comments (4)
- 建议用协议进行封装,例如Protobuf消息中的bytes字段就是[]byte
- 如果是类似rpc功能,cellnet有提供rpc封装,使用私有协议实现;如果是类似网关的透传封包数据relay包中有对应的实现
- 自己修改proc/tcp/transmitter中实现,将传入的msg类型断言为[]byte后重新按你期望的封包组包
from cellnet.
目前的需求是做一个socket服务器转发数据。客户端已经写好了,发送的只是byte数据,我这边只是做转发byte数据。
from cellnet.
更改了接收和发送的地方,是否会产生其他问题?
cellnet/util/packet.go 的SendLTVPacket函数:
`switch m := data.(type) {
case *cellnet.RawPacket: // 发裸包
msgData = m.MsgData
msgID = m.MsgID
case []byte:
//增加了[]byte判断
temp := reflect.ValueOf(data)
msgData = temp.Interface().([]byte)
msgID = 0
default: // 发普通编码包
var err error
// 将用户数据转换为字节数组和消息ID
msgData, meta, err = codec.EncodeMessage(data, ctx)
if err != nil {
return err
}
msgID = meta.ID
}`
cellnet/codec/msgcodec.go 的DecodeMessage函数
`func DecodeMessage(msgid int, data []byte) (interface{}, *cellnet.MessageMeta, error) {
// 获取消息元信息
//meta := cellnet.MessageMetaByID(msgid)
// 消息没有注册
//if meta == nil {
// return nil, nil, cellnet.NewErrorContext("msg not exists", msgid)
//}
// 创建消息
//msg := meta.NewType()
//
//// 从字节数组转换为消息
//err := meta.Codec.Decode(data, msg)
//
//if err != nil {
// return nil, meta, err
//}
return data, nil, nil
}`
from cellnet.
测下就好
from cellnet.
Related Issues (20)
- 请问怎么实现tsl支持 HOT 1
- 例子 HOT 2
- rpc怎么实现嵌套链式调用 HOT 4
- 网络层的小包读取都是readfull和new buffer gc开销会很严重
- 你好,非队列的rpc 处理能否放入独立的goroutine? HOT 2
- websocket
- websocket 链接失败
- 大佬 如何用json或者proto协议 作为数据传递 能否给个实列 HOT 1
- 请问v5版本有什么新特性么? HOT 2
- metaByID 不存在线程问题吗?
- 流量支持TLS加密接口吗 HOT 1
- Pipe的优化建议:减少Pick内的数据拷贝 HOT 1
- pipe.go里面Pick函数
- 请问cellnet适合用作物联网mqtt broker吗? HOT 1
- 没有使用go自带的channel是由于什么原因? HOT 1
- 服务端无法接受4M的请求 HOT 2
- 编解码器 codec 的一个 bug HOT 2
- 在SendLTVPacket里面每次发送都创建一个同样大小的pkt HOT 7
- writeList[0:0]会造成内存泄漏吗 HOT 4
- 有没有网关的实现列子 HOT 4
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 cellnet.