Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kick数据包类型并没有实现封装调用入口吗 #81

Open
lwelcom opened this issue Sep 13, 2021 · 3 comments
Open

Kick数据包类型并没有实现封装调用入口吗 #81

lwelcom opened this issue Sep 13, 2021 · 3 comments
Labels

Comments

@lwelcom
Copy link

lwelcom commented Sep 13, 2021

Question @lonng

// Kick represents a kick off packet
Kick = 0x05 // disconnect message from server

请问这个数据包类型并没有实现吗?
源码没有一个地方调用过该类型。应该需要额外加一个类似s.Response接口来处理Kick类型的数据包吧。

客户端虽然有这个数据包类型的定义接收,但是服务端没有实现这个数据包类型的封装?
handlers[Package.TYPE_KICK] = onKick;

@lwelcom lwelcom changed the title Kick数据包类型并没有实现吗 Kick数据包类型并没有实现封装调用入口吗 Sep 13, 2021
@lwelcom
Copy link
Author

lwelcom commented Sep 13, 2021

改造如下:
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 回包类型。

@lonng
Copy link
Owner

lonng commented Sep 13, 2021

Yes, Prefer

type NetworkEntity interface {
    Kick(v interface{}) error
}

@novel045
Copy link

novel045 commented Jan 4, 2024

type NetworkEntity interface {
    Kick(v interface{}) error
}
// Kick message to client
func (s *Session) Kick(v interface{}) error {
	return s.entity.Kick(v)
}
  1. message.go
  Kick Type = 0x04
  1. handler.go
	kick, err = codec.Encode(packet.Kick, nil)
	if err != nil {
		panic(err)
	}
  1. 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
			}
...省略
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants