|
|
|
@ -14,22 +14,24 @@ func Test_ServerTuAndClientCommon(t *testing.T) {
|
|
|
|
|
noEn := func(key, bn []byte) []byte {
|
|
|
|
|
return bn
|
|
|
|
|
}
|
|
|
|
|
_ = noEn
|
|
|
|
|
server := NewServer()
|
|
|
|
|
server.SetDefaultCommDecode(noEn)
|
|
|
|
|
server.SetDefaultCommEncode(noEn)
|
|
|
|
|
//server.SetDefaultCommDecode(noEn)
|
|
|
|
|
//server.SetDefaultCommEncode(noEn)
|
|
|
|
|
err := server.Listen("tcp", "127.0.0.1:12345")
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
server.SetLink("notify", notify)
|
|
|
|
|
for i := 1; i <= 5000; i++ {
|
|
|
|
|
for i := 1; i <= 100; i++ {
|
|
|
|
|
go func() {
|
|
|
|
|
client := NewClient()
|
|
|
|
|
client.SetMsgEn(noEn)
|
|
|
|
|
client.SetMsgDe(noEn)
|
|
|
|
|
client.SetSkipExchangeKey(true)
|
|
|
|
|
//client.SetMsgEn(noEn)
|
|
|
|
|
//client.SetMsgDe(noEn)
|
|
|
|
|
//client.SetSkipExchangeKey(true)
|
|
|
|
|
err = client.Connect("tcp", "127.0.0.1:12345")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
time.Sleep(time.Second * 2)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
@ -37,7 +39,8 @@ func Test_ServerTuAndClientCommon(t *testing.T) {
|
|
|
|
|
for {
|
|
|
|
|
|
|
|
|
|
//nowd = time.Now().UnixNano()
|
|
|
|
|
client.SendWait("notify", []byte("client hello"),time.Second*15)
|
|
|
|
|
client.SendWait("notify", []byte("client hello"), time.Second*15)
|
|
|
|
|
//client.Send("notify", []byte("client hello"))
|
|
|
|
|
//time.Sleep(time.Millisecond)
|
|
|
|
|
//fmt.Println("finished:", float64(time.Now().UnixNano()-nowd)/1000000)
|
|
|
|
|
//client.Send("notify", []byte("client"))
|
|
|
|
@ -65,7 +68,10 @@ func notify(msg *Message) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Test_normal(t *testing.T) {
|
|
|
|
|
server, _ := net.Listen("udp", "127.0.0.1:12345")
|
|
|
|
|
server, err := net.Listen("tcp", "127.0.0.1:12345")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
go func() {
|
|
|
|
|
for {
|
|
|
|
|
conn, err := server.Accept()
|
|
|
|
@ -87,7 +93,7 @@ func Test_normal(t *testing.T) {
|
|
|
|
|
time.Sleep(time.Second * 5)
|
|
|
|
|
for i := 1; i <= 100; i++ {
|
|
|
|
|
go func() {
|
|
|
|
|
conn, err := net.Dial("udp", "127.0.0.1:12345")
|
|
|
|
|
conn, err := net.Dial("tcp", "127.0.0.1:12345")
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|