新手学xingo golang服务器之-修改xingo 支持字符协议(一)
来源:互联网 发布:包月无限流量软件 编辑:程序博客网 时间:2024/06/06 02:23
新手学xingo golang服务器之-修改xingo 支持字符协议
git diff
查看我的修改:
--- a/fnet/datapack.go+++ b/fnet/datapack.go@@ -11,7 +11,7 @@ import ( type PkgData struct { Len uint32- MsgId uint32+ MsgId string Data []byte }diff --git a/fnet/msghandle.go b/fnet/msghandle.goold mode 100755new mode 100644index b1221a0..1d5aa91--- a/fnet/msghandle.go+++ b/fnet/msghandle.go@@ -7,7 +7,7 @@ import ( "fmt" "github.com/viphxin/xingo/logger" "github.com/viphxin/xingo/utils"- "strconv"+ _ "strconv" "time" "github.com/viphxin/xingo/iface" "runtime/debug"@@ -16,14 +16,14 @@ import ( type MsgHandle struct { PoolSize int32 TaskQueue []chan *Request- Apis map[uint32]iface.IRouter+ Apis map[string]iface.IRouter } func NewMsgHandle() *MsgHandle { return &MsgHandle{ PoolSize: utils.GlobalObject.PoolSize, TaskQueue: make([]chan *Request, utils.GlobalObject.PoolSize),- Apis: make(map[uint32]iface.IRouter),+ Apis: make(map[string]iface.IRouter), } }@@ -65,15 +65,16 @@ func (this *MsgHandle) DoMsgFromGoRoutine(pkg interface{}) { func (this *MsgHandle) AddRouter(name string, router iface.IRouter) { api := name- index, err := strconv.Atoi(api)- if err != nil {- panic("error api: " + api)- }- if _, ok := this.Apis[uint32(index)]; ok {+ // index, err := strconv.Atoi(api)+ index := name+ // if err != nil {+ // panic("error api: " + api)+ // }+ if _, ok := this.Apis[(index)]; ok { //存在 panic("repeated api " + string(index)) }- this.Apis[uint32(index)] = router+ this.Apis[(index)] = router logger.Info("add api " + api) }diff --git a/fnet/protocol.go b/fnet/protocol.goold mode 100755new mode 100644index e12d5af..e37759a--- a/fnet/protocol.go+++ b/fnet/protocol.go@@ -31,7 +31,7 @@ func (this *Request)GetData() []byte{ return this.Pdata.Data }-func (this *Request)GetMsgId() uint32{+func (this *Request)GetMsgId() string{ return this.Pdata.MsgId }diff --git a/iface/irouter.go b/iface/irouter.goindex 8cf16c9..ace54f9 100644--- a/iface/irouter.go+++ b/iface/irouter.go@@ -5,7 +5,7 @@ import "net/http" type IRequest interface { GetConnection() Iconnection GetData() []byte- GetMsgId() uint32+ GetMsgId() string }
“-“号删除
“+”号添加、修改
项目github地址:
https://github.com/atgczcl/xingo
测试:
//测试字符串协议 s.AddRouter("msg_load_bg", &api.Api_msg_dead_info_Router{})
go build server.go
./server.exe
运行起来后添加 字符串 msg_load_bg 协议成功,添加协议支持string,
封包,解包支持字符串,待续
阅读全文
0 0
- 新手学xingo golang服务器之-修改xingo 支持字符协议(一)
- 新手学xingo golang服务器之-修改xingo 支持字符协议(二)
- 新手学xingo golang服务器之-golang和unity3d的Protobuf生成(三)
- 我学xingo golang服务器之-XingoApi调用
- 我学xingo golang服务器之-xingo_demo server.go start
- 我学xingo golang服务器之-Unity3d c# 协议api分解
- 我学xingo golang服务器之-xingo的单进程,集群服务器的配置和初始化过程
- 我学xingo golang服务器之-xingo_demo 服务器游戏逻辑处理初始化过程
- 我学xingo golang服务器之-Unity3d c#多玩家同屏出生过程和AI处理分解
- 新手学LINUX下C++编程之路(一)
- 从零开始学写HTTP服务器(一)http协议简介
- <一>新手学opencv之cvSetMouseCallback笔记
- 新手学HighCharts(一)----基本使用
- 新手学Linux(一)----安装JDK
- 新手学PHP之-PHP运算符与应用(一)
- 新手学自定义View系列(一)之canvas绘制API
- Golang系列(一)之基础篇
- 新手从零开始学,相似图像匹配SIFT算法(一)
- OpenCV学习——读取usb摄像头或视频并按帧保存
- Copy List with Random Pointer (Frequent+)
- Greedy Match学习笔记一 —— 匹配原理及SAS实现
- POS机控件调用错误---Y5,与密码通讯失败
- 仿照Listview 优雅实现 RecyclerView的 HeaderView 和 FootView
- 新手学xingo golang服务器之-修改xingo 支持字符协议(一)
- TensorFlow关于 SSE AVX的Warning问题
- 修改Tomcat默认访问根目录
- 负值之美:负margin在页面布局中的应用
- 机器学习笔记:SVM
- AOP日志 记录方法参数名及对应值(包括对象和基本类型)
- PowerDesigner提示错误Non SQL Error : Could not load class com.mysql.jdbc.Driver
- JAVA注解的使用
- ajax 个人学习小记