Code Monkey home page Code Monkey logo

Comments (4)

davyxu avatar davyxu commented on May 4, 2024
  1. 建议用协议进行封装,例如Protobuf消息中的bytes字段就是[]byte
  2. 如果是类似rpc功能,cellnet有提供rpc封装,使用私有协议实现;如果是类似网关的透传封包数据relay包中有对应的实现
  3. 自己修改proc/tcp/transmitter中实现,将传入的msg类型断言为[]byte后重新按你期望的封包组包

from cellnet.

xiekelin avatar xiekelin commented on May 4, 2024

目前的需求是做一个socket服务器转发数据。客户端已经写好了,发送的只是byte数据,我这边只是做转发byte数据。

from cellnet.

xiekelin avatar xiekelin commented on May 4, 2024

更改了接收和发送的地方,是否会产生其他问题?
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.

davyxu avatar davyxu commented on May 4, 2024

测下就好

from cellnet.

Related Issues (20)

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.