Comments (3)
改造如下:
1 session.go文件增加对外暴露方法接口并实现
type NetworkEntity interface {
ResponseKick(v interface{}) error
}
2.实现
acceptor.go和agent.go 分别实现ResponseKick
message.go 增加一个类型 Kick = 0x04
3.回包的时候就指定回packet.Kick类型
func (a *agent) write() {
// packet encode
var packetType packet.Type
if data.typ == message.Kick {
packetType = packet.Kick
}else {
packetType = packet.Data
}
p, err := codec.Encode(packetType, em)
}
这样响应客户端就能通过如下解析
handlers[Package.TYPE_KICK] = onKick;
@lonng 这样合理吗, 因为你源码没有一个地方实现了Kick = 0x05 回包类型。
from nano.
Yes, Prefer
type NetworkEntity interface {
Kick(v interface{}) error
}
from nano.
type NetworkEntity interface {
Kick(v interface{}) error
}
// Kick message to client
func (s *Session) Kick(v interface{}) error {
return s.entity.Kick(v)
}
- message.go
Kick Type = 0x04
- handler.go
kick, err = codec.Encode(packet.Kick, nil)
if err != nil {
panic(err)
}
- agent.go
func (a *agent) Kick(v interface{}) error {
if a.status() == statusClosed {
return ErrBrokenPipe
}
return a.send(pendingMessage{typ: message.Kick})
}
func(a * agent)write(){
...省略
if data.typ == message.Kick {
chWrite <- kick
break
}
...省略
}
from nano.
Related Issues (20)
- cluster模式下 调用rpc error好像永远返回nil
- ws 的 RemoteAddr() 丢失了http相关的信息 反向代理无法获取客户端IP
- 能讲下将lua 引入到组件中的具体构思吗?让想实现的人去实现一下
- 能讲下将lua 引入到组件中的具体构思吗?让想实现的人去实现一下
- 多节点情况下,在网关session 断线后,其它节点保存的session信息如何删除?
- 关于不同节点调用传递的sessionId,为什么多节点的session 对象不直接使用同一个sessionId进行匹配?
- Server间如何不透过session进行rpc?
- cluster模式,s.RPC通讯不能获取到另一个服务的错误 HOT 2
- Why need a session to make an rpc call?
- nano should add uid in gRPC request HOT 2
- What is the cluster restart sequence after a code change?
- 如何拓展使用MongoDB?
- 多Gate sessionId 无法保证全局唯一 HOT 1
- C端长链 agent 长期发送包,是否会导致 Decode 里面的Buffer 不会释放,导致内存泄露
- 未来是否会支持KCP协议?
- 服务多开怎么处理group
- rpc没有返回 HOT 3
- 支持libpomelo吗?
- examples 有很强的误导性
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 nano.