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