|
|
|
@ -5,7 +5,7 @@ import (
|
|
|
|
|
"git.noahlan.cn/noahlan/nnet/config"
|
|
|
|
|
"git.noahlan.cn/noahlan/nnet/entity"
|
|
|
|
|
"git.noahlan.cn/noahlan/nnet/packet"
|
|
|
|
|
"git.noahlan.cn/noahlan/nnet/protocol"
|
|
|
|
|
"git.noahlan.cn/noahlan/nnet/protocol/nnet"
|
|
|
|
|
"git.noahlan.cn/noahlan/ntools-go/core/nlog"
|
|
|
|
|
"git.noahlan.cn/noahlan/ntools-go/core/pool"
|
|
|
|
|
"math"
|
|
|
|
@ -29,19 +29,19 @@ func TestServer(t *testing.T) {
|
|
|
|
|
Nonblocking: false,
|
|
|
|
|
DisablePurge: false,
|
|
|
|
|
},
|
|
|
|
|
}, protocol.WithNNetProtocol(protocol.NNetConfig{
|
|
|
|
|
}, nnet.WithNNetProtocol(nnet.Config{
|
|
|
|
|
HeartbeatInterval: 0,
|
|
|
|
|
HandshakeValidator: nil,
|
|
|
|
|
})...)
|
|
|
|
|
|
|
|
|
|
server.AddRoute(Route{
|
|
|
|
|
Matches: protocol.Match{
|
|
|
|
|
Matches: nnet.Match{
|
|
|
|
|
Route: "test",
|
|
|
|
|
Code: 1,
|
|
|
|
|
},
|
|
|
|
|
Handler: func(entity entity.NetworkEntity, pkg packet.IPacket) {
|
|
|
|
|
fmt.Println(pkg)
|
|
|
|
|
p, ok := pkg.(*protocol.NNetPacket)
|
|
|
|
|
p, ok := pkg.(*nnet.Packet)
|
|
|
|
|
if !ok {
|
|
|
|
|
nlog.Error("wrong packet type")
|
|
|
|
|
return
|
|
|
|
@ -49,11 +49,11 @@ func TestServer(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
bd := []byte("服务器接收到数据为: " + string(p.GetBody()))
|
|
|
|
|
// 注:Response类型数据不需要Route(原地返回,客户端需等待)
|
|
|
|
|
_ = entity.Send(protocol.Header{
|
|
|
|
|
PacketType: protocol.Data,
|
|
|
|
|
_ = entity.Send(nnet.Header{
|
|
|
|
|
PacketType: nnet.Data,
|
|
|
|
|
Length: uint32(len(bd)),
|
|
|
|
|
MessageHeader: protocol.MessageHeader{
|
|
|
|
|
MsgType: protocol.Response,
|
|
|
|
|
MessageHeader: nnet.MessageHeader{
|
|
|
|
|
MsgType: nnet.Response,
|
|
|
|
|
ID: p.ID,
|
|
|
|
|
Route: p.Route,
|
|
|
|
|
},
|
|
|
|
|