package notify import ( "fmt" "testing" "time" ) func Test_usechannel(t *testing.T) { server, err := NewNotifyS("udp", "127.0.0.1:1926") if err != nil { fmt.Println(err) return } server.SetNotify("nihao", func(data SMsg) string { fmt.Println("server recv:", data.Key, data.Value) if data.Value != "" { data.Reply("nba") return "nb" } return "" }) client, err := NewNotifyC("udp", "127.0.0.1:1926") if err != nil { fmt.Println(err) return } //time.Sleep(time.Second * 10) client.Send("nihao") client.SendValue("nihao", "lalala") txt := <-client.Notify("nihao") fmt.Println("client", txt) txt = <-client.Notify("nihao") fmt.Println("client", txt) server.ServerStop() <-client.Stop client.ClientStop() time.Sleep(time.Second * 3) } func Test_nochannel(t *testing.T) { server, err := NewNotifyS("udp", "127.0.0.1:1926") if err != nil { fmt.Println(err) return } server.SetNotify("nihao", func(data SMsg) string { fmt.Println("server recv:", data.Key, data.Value) if data.Value != "" { data.Reply("nba") return "nb" } return "" }) client, err := NewNotifyC("udp", "127.0.0.1:1926") if err != nil { fmt.Println(err) return } //time.Sleep(time.Second * 10) client.UseChannel = false client.SetNotify("nihao", func(data CMsg) { fmt.Println("client recv:", data.Key, data.Value) if data.Value != "" { time.Sleep(time.Millisecond * 900) client.SendValue("nihao", "dsb") } }) client.SendValue("nihao", "lalala") time.Sleep(time.Second * 3) server.ServerStop() <-client.Stop client.ClientStop() time.Sleep(time.Second * 3) }