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