func TestTcpService(t *testing.T) { server := hprose.NewTcpServer("") server.AddFunction("hello", hello) server.AddMethods(new(testServe)) go server.Start() defer server.Close() client := hprose.NewClient(server.URL) var ro *testRemoteObject2 client.UseService(&ro) if s, err := ro.Hello("World"); err != nil { t.Error(err.Error()) } else { fmt.Println(s) } if a, b, err := ro.Swap(1, 2); err != nil { t.Error(err.Error()) } else { fmt.Println(a, b) } if sum, err := ro.Sum(1); err != nil { fmt.Println(err.Error()) } else { t.Error(sum) } if sum, err := ro.Sum(1, 2, 3, 4, 5); err != nil { t.Error(err.Error()) } else { fmt.Println(sum) } if err := ro.PanicTest(); err != nil { fmt.Println(err.Error()) } else { t.Error("missing panic") } }
func main() { server := hprose.NewTcpServer("tcp4://0.0.0.0:4321/") server.AddFunction("hello", hello) server.Start() b := make([]byte, 1) os.Stdin.Read(b) server.Stop() }
func main() { server := hprose.NewTcpServer("tcp4://:4321/") server.AddFilter(MyServerFilter{}) server.AddFunction("inc", inc) server.ThreadCount = 16 server.Start() b := make([]byte, 1) os.Stdin.Read(b) server.Stop() }
func main() { server := hprose.NewTcpServer("tcp4://0.0.0.0:4321/") server.AddFunction("cvft", CreateVmsFromTpl) server.Start() for { time.Sleep(1 * time.Second) } server.Stop() }
func main() { server := hprose.NewTcpServer("tcp4://0.0.0.0:4321/") server.AddFunction("vmstl", VmsTemplateList) server.AddFunction("cvft", CreateVmsFromTpl) server.AddFunction("delvms", DelVmsInstanceByUuid) server.AddFunction("getvmsip", GetVmsIp) server.Start() for { time.Sleep(1) } server.Stop() }
func TestTcpServiceAsync(t *testing.T) { server := hprose.NewTcpServer("") server.AddFunction("hello", hello) server.AddMethods(new(testServe)) server.Start() defer server.Stop() client := hprose.NewClient(server.URL) var ro *testRemoteObject3 client.UseService(&ro) s, err1 := ro.Hello("World") a, b, err2 := ro.Swap(1, 2) sum1, err3 := ro.Sum(1) if err := <-err1; err != nil { t.Error(err.Error()) } else { fmt.Println(<-s) } if err := <-err2; err != nil { t.Error(err.Error()) } else { fmt.Println(<-a, <-b) } if err := <-err3; err != nil { fmt.Println(err.Error()) } else { t.Error(<-sum1) } sum2, err4 := ro.Sum(1, 2, 3, 4, 5) err5 := ro.PanicTest() if err := <-err4; err != nil { t.Error(err.Error()) } else { fmt.Println(<-sum2) } if err := <-err5; err != nil { fmt.Println(err.Error()) } else { t.Error("missing panic") } }