1d14da4a2b60bd32f2aa76359c213d2be5c5533f.svn-base 710 B

1234567891011121314151617181920212223242526272829
  1. package main
  2. import (
  3. "fmt"
  4. service "github.com/longjoy/micro-go-course/section16/service"
  5. "log"
  6. "net/rpc"
  7. )
  8. func main() {
  9. client, err := rpc.DialHTTP("tcp", "127.0.0.1:1234")
  10. if err != nil {
  11. log.Fatal("dialing:", err)
  12. }
  13. stringReq := &service.StringRequest{"A", "B"}
  14. var reply string
  15. err = client.Call("StringService.Concat", stringReq, &reply)
  16. fmt.Printf("StringService Concat : %s concat %s = %s\n", stringReq.A, stringReq.B, reply)
  17. if err != nil {
  18. log.Fatal("Concat error:", err)
  19. }
  20. // 异步的调用方式
  21. call := client.Go("StringService.Concat", stringReq, &reply, nil)
  22. _ = <-call.Done
  23. fmt.Printf("StringService Concat : %s concat %s = %s\n", stringReq.A, stringReq.B, reply)
  24. }