package main import ( "git.noahlan.cn/noahlan/nnet/conn" "git.noahlan.cn/noahlan/nnet/packet" "git.noahlan.cn/noahlan/nnet/protocol/nnet" rt "git.noahlan.cn/noahlan/nnet/router" "git.noahlan.cn/noahlan/ntool/nlog" "sync" "testing" ) func TestServer(t *testing.T) { runServer("0.0.0.0:6666") } func TestClient(t *testing.T) { ngin, et := runClient("127.0.0.1:6666") ngin.AddRoutes(rt.Route{ Matches: nnet.Match{ Route: "pong", Code: 2, }, Handler: func(conn *conn.Connection, 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() }