當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Client.Go方法代碼示例

本文整理匯總了Golang中net/rpc.Client.Go方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.Go方法的具體用法?Golang Client.Go怎麽用?Golang Client.Go使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在net/rpc.Client的用法示例。


在下文中一共展示了Client.Go方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Client

func Client() {
	var err error
	var c net.Conn
	c, err = net.DialTimeout("tcp", "127.0.0.1:1234", 1000*1000*1000*30)
	if err != nil {
		log.Fatal("dialing:", err)
	}

	var client *rpc.Client
	client = jsonrpc.NewClient(c)

	// 同步
	var args *Args = &Args{7, 8}
	var reply *Data = new(Data)
	client.Call("Arith.Plus", args, reply)
	fmt.Println(reply)

	// 異步
	args.A = 1
	args.B = 2
	var call *rpc.Call
	call = client.Go("Arith.Plus", args, reply, nil)
	var doneCall *rpc.Call
	doneCall = <-call.Done
	fmt.Println(doneCall.Args, doneCall.Reply)
	fmt.Println(args, reply)

	client.Close()
	c.Close()
}
開發者ID:fengzai,項目名稱:snippet,代碼行數:30,代碼來源:rpc-client.go

示例2: accept

func (pn *paxosNode) accept(client *rpc.Client, args *paxosrpc.AcceptArgs, reply *paxosrpc.AcceptReply, reqChan chan voteRequest) {
	finChan := make(chan *rpc.Call, pn.numNodes)
	client.Go("PaxosNode.RecvAccept", args, reply, finChan)
	call := <-finChan
	if call.Reply.(*paxosrpc.AcceptReply).Status == paxosrpc.OK {
		reqChan <- voteRequest{vote: true}
	} else {
		reqChan <- voteRequest{vote: false}
	}
}
開發者ID:wentianqi7,項目名稱:15640-distributed-systems,代碼行數:10,代碼來源:paxos_impl.go

示例3: ApiQuery

func ApiQuery(w http.ResponseWriter, r *http.Request) {

	defer func() {
		//r.Body.Close()
	}()

	//_, err := ioutil.ReadAll(r.Body)
	//if err != nil {
	//    return
	//}

	var err error

	status := make(chan int, 2)

	go func() {

		var sock *rpc.Client
		if sock, err = rpc.DialHTTP("tcp", "localhost:9601"); err != nil {
			return
		}
		defer sock.Close()

		//r  := new(CommandReply)
		var rsp CommandReply
		rs := sock.Go("Command.Query", "nil", &rsp, nil)

		select {
		case <-rs.Done:
			status <- 1
		case <-time.After(3e9):
			status <- 9
		}

		//runtime.Goexit()
		return
	}()

	for {
		select {
		case <-status:
			goto L
		case <-time.After(3e9):
			goto L
		}
	}

L:
	//io.WriteString(w, "{\"status\": \"OK\"}")
	close(status)

	return
}
開發者ID:eryx,項目名稱:tips.go,代碼行數:53,代碼來源:http-httprpc-server.go

示例4: prepare

func (pn *paxosNode) prepare(client *rpc.Client, args *paxosrpc.PrepareArgs, reply *paxosrpc.PrepareReply, reqChan chan voteRequest) {
	finChan := make(chan *rpc.Call, pn.numNodes)
	client.Go("PaxosNode.RecvPrepare", args, reply, finChan)
	call := <-finChan

	pReply := call.Reply.(*paxosrpc.PrepareReply)
	if pReply.Status == paxosrpc.OK {
		reqChan <- voteRequest{true, pReply.N_a, pReply.V_a}
	} else {
		reqChan <- voteRequest{false, pReply.N_a, pReply.V_a}
	}
}
開發者ID:wentianqi7,項目名稱:15640-distributed-systems,代碼行數:12,代碼來源:paxos_impl.go

示例5: GetWin32Service

func GetWin32Service(client *rpc.Client) {
	var reply []Win32_Service
	args := "test"

	call := client.Go("Win32_Service.GetWin32Service", args, &reply, nil)

	replyCall := <-call.Done
	if replyCall.Error != nil {
		log.Fatal("GetWin32Service.replyCall.Error:", replyCall.Error)
	}
	for i, v := range reply {
		fmt.Println(i, v.Name, v.State)
	}
}
開發者ID:iamxeph,項目名稱:golang,代碼行數:14,代碼來源:main.go

示例6: GetWin32Process

func GetWin32Process(client *rpc.Client) {
	var reply []Win32_Process
	args := "test"

	call := client.Go("Win32_Process.GetWin32Process", args, &reply, nil)

	replyCall := <-call.Done
	if replyCall.Error != nil {
		log.Fatal("GetWin32Process.replyCall.Error:", replyCall.Error)
	}
	for i, v := range reply {
		fmt.Println(i, v.Name)
	}
}
開發者ID:iamxeph,項目名稱:golang,代碼行數:14,代碼來源:main.go

示例7: rpc_call

func rpc_call(client *rpc.Client, method string, args interface{},
	reply interface{}, timeout time.Duration) error {
	done := make(chan *rpc.Call, 1)
	client.Go(method, args, reply, done)
	select {
	case <-time.After(timeout):
		return errors.New("i/o timeout[rpc]")
	case call := <-done:
		if call.Error == nil {
			return nil
		} else {
			return call.Error
		}
	}
}
開發者ID:modeyang,項目名稱:graph,代碼行數:15,代碼來源:migrate.go

示例8: testEchoClientAsync

func testEchoClientAsync(t *testing.T, client *rpc.Client) {
	// EchoService.Echo
	args := &message.EchoRequest{Msg: "Hello, Protobuf-RPC"}
	reply := &message.EchoResponse{}
	echoCall := client.Go("EchoService.Echo", args, reply, nil)

	// EchoService.Echo reply
	echoCall = <-echoCall.Done
	if echoCall.Error != nil {
		t.Fatalf(`EchoService.Echo: %v`, echoCall.Error)
	}
	if echoCall.Reply.(*message.EchoResponse).GetMsg() != args.GetMsg() {
		t.Fatalf(`EchoService.Echo: expected = "%s", got = "%s"`,
			args.GetMsg(),
			echoCall.Reply.(*message.EchoResponse).GetMsg(),
		)
	}
}
開發者ID:Hellblazer,項目名稱:cockroach,代碼行數:18,代碼來源:rpc_test.go

示例9: MakeAsyncCall

// MakeAsyncCall calls a function at a remote peer 'callee' asynchronously. The three last arguments
// are identical to that of net/rpc's '(client *Client) Go' function.
func (rpcServ *RPCService) MakeAsyncCall(callee *Peer, call string, args interface{}, result interface{}) *rpc.Call {
	if callee == nil {
		return nil
	}
	// Check if there is already a connection
	var client *rpc.Client

	rpcServ.RLock()
	client = rpcServ.clientMap[callee.Address]
	rpcServ.RUnlock()

	// Open if not
	var err error
	if client == nil {
		client, err = rpcServ.rpcConnect(callee)
		if err != nil {
			fmt.Println("RPC Connect failed!")
			return nil
		}
	}
	asyncCall := client.Go("Node."+call, args, result, nil)

	return asyncCall
}
開發者ID:DiegoAlbertoTorres,項目名稱:alternator,代碼行數:26,代碼來源:rpc.go

示例10: testArithClientAsync

func testArithClientAsync(t *testing.T, client *rpc.Client) {
	done := make(chan *rpc.Call, 16)
	callInfoList := []struct {
		method string
		args   *msg.ArithRequest
		reply  *msg.ArithResponse
		err    error
	}{
		{
			"ArithService.Add",
			&msg.ArithRequest{A: proto.Int32(1), B: proto.Int32(2)},
			&msg.ArithResponse{C: proto.Int32(3)},
			nil,
		},
		{
			"ArithService.Mul",
			&msg.ArithRequest{A: proto.Int32(2), B: proto.Int32(3)},
			&msg.ArithResponse{C: proto.Int32(6)},
			nil,
		},
		{
			"ArithService.Div",
			&msg.ArithRequest{A: proto.Int32(13), B: proto.Int32(5)},
			&msg.ArithResponse{C: proto.Int32(2)},
			nil,
		},
		{
			"ArithService.Div",
			&msg.ArithRequest{A: proto.Int32(1), B: proto.Int32(0)},
			&msg.ArithResponse{},
			errors.New("divide by zero"),
		},
		{
			"ArithService.Error",
			&msg.ArithRequest{A: proto.Int32(1), B: proto.Int32(2)},
			&msg.ArithResponse{},
			errors.New("ArithError"),
		},
	}

	// GoCall list
	calls := make([]*rpc.Call, len(callInfoList))
	for i := 0; i < len(calls); i++ {
		calls[i] = client.Go(callInfoList[i].method,
			callInfoList[i].args, callInfoList[i].reply,
			done,
		)
	}
	for i := 0; i < len(calls); i++ {
		<-calls[i].Done
	}

	// check result
	for i := 0; i < len(calls); i++ {
		if callInfoList[i].err != nil {
			if calls[i].Error.Error() != callInfoList[i].err.Error() {
				t.Fatalf(`%s: expected %v, Got = %v`,
					callInfoList[i].method,
					callInfoList[i].err,
					calls[i].Error,
				)
			}
			continue
		}

		got := calls[i].Reply.(*msg.ArithResponse).GetC()
		expected := callInfoList[i].reply.GetC()
		if got != expected {
			t.Fatalf(`%v: expected %v, Got = %v`,
				callInfoList[i].method, got, expected,
			)
		}
	}
}
開發者ID:jimmyyan,項目名稱:protorpc,代碼行數:74,代碼來源:rpc_test.go

示例11: commit

func (pn *paxosNode) commit(client *rpc.Client, args *paxosrpc.CommitArgs, reply *paxosrpc.CommitReply, reqChan chan voteRequest) {
	finChan := make(chan *rpc.Call, pn.numNodes)
	go client.Go("PaxosNode.RecvCommit", args, reply, finChan)
	<-finChan
	reqChan <- voteRequest{vote: true}
}
開發者ID:wentianqi7,項目名稱:15640-distributed-systems,代碼行數:6,代碼來源:paxos_impl.go


注:本文中的net/rpc.Client.Go方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。