GithubHelp home page GithubHelp logo

Comments (3)

lwelcom avatar lwelcom commented on July 19, 2024

改造如下:
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.

lonng avatar lonng commented on July 19, 2024

Yes, Prefer

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

from nano.

novel045 avatar novel045 commented on July 19, 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
			}
...省略
}

from nano.

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.