package main import ( "git.noahlan.cn/noahlan/nnet/core" "git.noahlan.cn/noahlan/nnet/entity" "git.noahlan.cn/noahlan/nnet/packet" "git.noahlan.cn/noahlan/nnet/protocol/nnet" "git.noahlan.cn/noahlan/ntools-go/core/nlog" "sync" "testing" ) func TestServer(t *testing.T) { runServer("0.0.0.0:6666") } func TestClient(t *testing.T) { client, et := runClient("127.0.0.1:6666") client.AddRoute(core.Route{ Matches: nnet.Match{ Route: "pong", Code: 2, }, Handler: func(et entity.NetworkEntity, pkg packet.IPacket) { nlog.Info("server pong, client ping ->") _ = et.Send(nnet.Header{ PacketType: nnet.Data, MessageHeader: nnet.MessageHeader{ MsgType: nnet.Request, ID: 1, Route: "ping", }, }, []byte("1")) }, }) _ = et.Send(nnet.Header{ PacketType: nnet.Data, MessageHeader: nnet.MessageHeader{ MsgType: nnet.Request, ID: 1, Route: "ping", }, }, []byte("1")) var wg sync.WaitGroup wg.Add(1) wg.Wait() }