• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang protorpc.Dial函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/Terry-Mao/protorpc.Dial函数的典型用法代码示例。如果您正苦于以下问题:Golang Dial函数的具体用法?Golang Dial怎么用?Golang Dial使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Dial函数的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: InitCometRpc

func InitCometRpc(addrs map[int32]string) (err error) {
	for serverID, addrs := range addrs {
		var (
			rpcClient     *protorpc.Client
			quit          chan struct{}
			network, addr string
		)
		if network, addr, err = inet.ParseNetwork(addrs); err != nil {
			log.Error("inet.ParseNetwork() error(%v)", err)
			return
		}
		rpcClient, err = protorpc.Dial(network, addr)
		if err != nil {
			log.Error("protorpc.Dial(\"%s\") error(%s)", addr, err)
			return
		}

		go protorpc.Reconnect(&rpcClient, quit, network, addr)
		log.Info("rpc addr:%s connected", addr)

		cometServiceMap[serverID] = &rpcClient
	}

	return
}
开发者ID:huweixuan,项目名称:goim,代码行数:25,代码来源:comet.go


示例2: InitRouter

func InitRouter() (err error) {
	var (
		network, addr string
	)
	routerRing = ketama.NewRing(ketama.Base)
	for serverId, addrs := range Conf.RouterRPCAddrs {
		// WARN r must every recycle changed for reconnect
		var (
			r          *rpc.Client
			routerQuit = make(chan struct{}, 1)
		)
		if network, addr, err = inet.ParseNetwork(addrs); err != nil {
			log.Error("inet.ParseNetwork() error(%v)", err)
			return
		}
		r, err = rpc.Dial(network, addr)
		if err != nil {
			log.Error("rpc.Dial(\"%s\", \"%s\") error(%s)", network, addr, err)
		}
		go rpc.Reconnect(&r, routerQuit, network, addr)
		log.Debug("router rpc addr:%s connect", addr)
		routerServiceMap[serverId] = &r
		routerRing.AddNode(serverId, 1)
	}
	routerRing.Bake()
	return
}
开发者ID:nevermatch,项目名称:goim,代码行数:27,代码来源:router.go


示例3: TestRouterConnect

func TestRouterConnect(t *testing.T) {
	c, err := rpc.Dial("tcp", "localhost:7270")
	if err != nil {
		t.Error(err)
		t.FailNow()
	}
	arg := &proto.ConnArg{}
	reply := &proto.ConnReply{}
	arg.UserId = 1
	arg.Server = 0
	if err = c.Call("RouterRPC.Connect", arg, reply); err != nil {
		t.Error(err)
		t.FailNow()
	}
	if reply.Seq != 1 {
		t.Errorf("reply seq: %d not equal 0", reply.Seq)
		t.FailNow()
	}
	arg.UserId = 1
	arg.Server = 0
	if err = c.Call("RouterRPC.Connect", arg, reply); err != nil {
		t.Error(err)
		t.FailNow()
	}
	if reply.Seq != 2 {
		t.Errorf("reply seq: %d not equal 1", reply.Seq)
		t.FailNow()
	}
}
开发者ID:dulumao,项目名称:goim,代码行数:29,代码来源:router_test.go


示例4: TestRouterGet

func TestRouterGet(t *testing.T) {
	c, err := rpc.Dial("tcp", "localhost:7270")
	if err != nil {
		t.Error(err)
		t.FailNow()
	}

	arg := &proto.GetArg{}
	reply := &proto.GetReply{}
	arg.UserId = 1
	if err = c.Call("RouterRPC.Get", arg, reply); err != nil {
		t.Error(err)
		t.FailNow()
	}
	if len(reply.Seqs) != 2 || len(reply.Servers) != 2 {
		t.Errorf("reply seqs||servers length not equals 2")
		t.FailNow()
	}
	if reply.Seqs[0] != 1 || reply.Seqs[1] != 2 {
		t.Error("reply seqs not match")
		t.FailNow()
	}
	if reply.Servers[0] != 0 || reply.Servers[1] != 0 {
		t.Errorf("reply servers not match, %v", reply.Servers)
		t.FailNow()
	}
}
开发者ID:dulumao,项目名称:goim,代码行数:27,代码来源:router_test.go


示例5: TestRouterDisconnect

func TestRouterDisconnect(t *testing.T) {
	c, err := rpc.Dial("tcp", "localhost:7270")
	if err != nil {
		t.Error(err)
		t.FailNow()
	}
	arg := &proto.ConnArg{}
	reply := &proto.ConnReply{}
	arg.UserId = 2
	arg.Server = 0
	if err = c.Call("RouterRPC.Connect", arg, reply); err != nil {
		t.Error(err)
		t.FailNow()
	}
	if reply.Seq != 1 {
		t.Errorf("reply seq: %d not equal 0", reply.Seq)
		t.FailNow()
	}
	arg1 := &proto.DisconnArg{}
	arg1.UserId = 2
	arg1.Seq = 1
	reply1 := &proto.DisconnReply{}
	if err = c.Call("RouterRPC.Disconnect", arg1, reply1); err != nil {
		t.Error(err)
		t.FailNow()
	}
	if !reply1.Has {
		t.Errorf("reply has: %d not equal true", reply1.Has)
		t.FailNow()
	}
}
开发者ID:dulumao,项目名称:goim,代码行数:31,代码来源:router_test.go


示例6: InitLogicRpc

func InitLogicRpc(network, addr string) (err error) {
	logicRpcClient, err = protorpc.Dial(network, addr)
	if err != nil {
		log.Error("rpc.Dial(\"%s\", \"%s\") error(%s)", network, addr, err)
	}
	go protorpc.Reconnect(&logicRpcClient, logicRpcQuit, network, addr)
	log.Debug("logic rpc addr %s:%s connected", network, addr)
	return
}
开发者ID:nevermatch,项目名称:goim,代码行数:9,代码来源:logic.go


示例7: InitLogicRpc

func InitLogicRpc(addr string, retry time.Duration) (err error) {
	logicRpcClient, err = protorpc.Dial("tcp", addr)
	if err != nil {
		log.Error("rpc.Dial(\"%s\") error(%s)", addr, err)
		return
	}
	go rpcPing(addr, logicRpcClient, retry)
	log.Debug("logic rpc addr:%s connected", addr)

	return
}
开发者ID:sf100,项目名称:goim,代码行数:11,代码来源:logic.go


示例8: InitLogicRpc

func InitLogicRpc(addrs string) (err error) {
	var network, addr string
	if network, addr, err = inet.ParseNetwork(addrs); err != nil {
		log.Error("inet.ParseNetwork() error(%v)", err)
		return
	}
	logicRpcClient, err = protorpc.Dial(network, addr)
	if err != nil {
		log.Error("rpc.Dial(\"%s\", \"%s\") error(%s)", network, addr, err)
	}
	go protorpc.Reconnect(&logicRpcClient, logicRpcQuit, network, addr)
	log.Debug("logic rpc addr %s:%s connected", network, addr)
	return
}
开发者ID:hudangwei,项目名称:goim,代码行数:14,代码来源:logic.go


示例9: testNewServerRPC

func testNewServerRPC(t *testing.T, addr string) {
	client, err := protorpc.Dial("tcp", addr)
	if err != nil {
		t.Fatal("dialing", err)
	}
	defer client.Close()

	// Synchronous calls
	args := &Args{7, 8}
	reply := new(Reply)
	err = client.Call("newServer.Arith.Add", args, reply)
	if err != nil {
		t.Errorf("Add: expected no error but got string %q", err.Error())
	}
	if reply.C != args.A+args.B {
		t.Errorf("Add: expected %d got %d", reply.C, args.A+args.B)
	}
}
开发者ID:scabwort,项目名称:protorpc,代码行数:18,代码来源:server_test.go


示例10: InitRouterRpc

func InitRouterRpc(addrs []string, retry time.Duration) (err error) {
	var r *rpc.Client
	routerRing = ketama.NewRing(ketama.Base)
	for _, addr := range addrs {
		r, err = rpc.Dial("tcp", addr)
		if err != nil {
			log.Error("rpc.Dial(\"%s\") error(%s)", addr, err)
			return
		}
		go rpcPing(addr, r, retry)
		log.Debug("router rpc addr:%s connect", addr)
		routerServiceMap[addr] = r
		routerRing.AddNode(addr, 1)
	}
	routerRing.Bake()

	return
}
开发者ID:sf100,项目名称:goim,代码行数:18,代码来源:router.go


示例11: InitRouterRpc

func InitRouterRpc(addrs []string) (err error) {
	var r *protorpc.Client
	routerRing = ketama.NewRing(ketama.Base)
	for _, addr := range addrs {
		r, err = protorpc.Dial("tcp", addr)
		if err != nil {
			log.Error("protorpc.Dial(\"%s\") error(%s)", addr, err)
			return
		}
		var quit chan struct{}
		go protorpc.Reconnect(&r, quit, "tcp", addr)
		log.Debug("router protorpc addr:%s connect", addr)
		routerServiceMap[addr] = r
		routerRing.AddNode(addr, 1)
	}
	routerRing.Bake()

	return
}
开发者ID:huweixuan,项目名称:goim,代码行数:19,代码来源:router.go


示例12: rpcPing

func rpcPing(addr string, c *protorpc.Client, retry time.Duration) {
	var err error
	for {
		if err = c.Call(logicServicePing, nil, nil); err != nil {
			log.Error("c.Call(\"%s\", nil, nil) error(%v), retry after:%ds", logicServicePing, err, retry/time.Second)
			rpcTmp, err := protorpc.Dial("tcp", addr)
			if err != nil {
				log.Error("protorpc.Dial(\"tcp\", %s) error(%v)", addr, err)
				time.Sleep(retry)
				continue
			}
			c = rpcTmp
			time.Sleep(retry)
			continue
		}
		log.Debug("rpc ping:%s ok", addr)
		time.Sleep(retry)
		continue
	}
}
开发者ID:sf100,项目名称:goim,代码行数:20,代码来源:logic.go


示例13: InitRouter

func InitRouter() (err error) {
	var (
		r *rpc.Client
		i = 0
	)
	routerRing = ketama.NewRing(ketama.Base)
	for serverId, addr := range Conf.RouterRPCAddrs {
		r, err = rpc.Dial(Conf.RouterRPCNetworks[i], addr)
		if err != nil {
			log.Error("rpc.Dial(\"%s\", \"%s\") error(%s)", Conf.RouterRPCNetworks[i], addr, err)
			return
		}
		go rpc.Reconnect(&r, routerQuit, Conf.RouterRPCNetworks[i], addr)
		log.Debug("router rpc addr:%s connect", addr)
		routerServiceMap[serverId] = r
		routerRing.AddNode(serverId, 1)
		i++
	}
	routerRing.Bake()
	return
}
开发者ID:sinuos,项目名称:goim,代码行数:21,代码来源:router.go


示例14: TestProtoError

func TestProtoError(t *testing.T) {
	if runtime.GOOS == "plan9" {
		t.Skip("skipping test; see http://golang.org/issue/8908")
	}
	defer func() {
		err := recover()
		if err == nil {
			t.Fatal("no error")
		}
		if !strings.Contains("reading body proto: wrong wireType = 2 for field C", err.(error).Error()) {
			t.Fatal("expected proto', got", err)
		}
	}()
	protorpc.Register(new(S))

	listen, err := net.Listen("tcp", "127.0.0.1:0")
	if err != nil {
		panic(err)
	}
	go protorpc.Accept(listen)

	client, err := protorpc.Dial("tcp", listen.Addr().String())
	if err != nil {
		panic(err)
	}

	go client.Ping(&client)
	var reply Reply
	err = client.Call("S.Recv", nil, &reply)
	if err != nil {
		panic(err)
	}

	fmt.Printf("%#v\n", reply)
	client.Close()

	listen.Close()
}
开发者ID:wmydz1,项目名称:protorpc,代码行数:38,代码来源:client_test.go


示例15: dialDirect

func dialDirect() (*protorpc.Client, error) {
	return protorpc.Dial("tcp", serverAddr)
}
开发者ID:scabwort,项目名称:protorpc,代码行数:3,代码来源:server_test.go


示例16: testRPC

func testRPC(t *testing.T, addr string) {
	client, err := protorpc.Dial("tcp", addr)
	if err != nil {
		t.Fatal("dialing", err)
	}
	defer client.Close()

	// Synchronous calls
	log.Println("Synchronous calls")
	args := &Args{7, 8}
	reply := new(Reply)
	err = client.Call("Arith.Add", args, reply)
	if err != nil {
		t.Errorf("Add: expected no error but got string %q", err.Error())
	}
	if reply.C != args.A+args.B {
		t.Errorf("Add: expected %d got %d", reply.C, args.A+args.B)
	}

	// Nonexistent method
	log.Println("Nonexistent method")
	args = &Args{7, 0}
	reply = new(Reply)
	err = client.Call("Arith.BadOperation", args, reply)
	// expect an error
	if err == nil {
		t.Error("BadOperation: expected error")
	} else if !strings.HasPrefix(err.Error(), "rpc: can't find method ") {
		t.Errorf("BadOperation: expected can't find method error; got %q", err)
	}

	// Unknown service
	log.Println("Unknown service")
	args = &Args{7, 8}
	reply = new(Reply)
	err = client.Call("Arith.Unknown", args, reply)
	if err == nil {
		t.Error("expected error calling unknown service")
	} else if strings.Index(err.Error(), "method") < 0 {
		t.Error("expected error about method; got", err)
	}

	// Out of order.
	log.Println("Out of order")
	args = &Args{7, 8}
	mulReply := new(Reply)
	log.Println("Aritu.Mul")
	mulCall := client.Go("Arith.Mul", args, mulReply, nil)
	addReply := new(Reply)
	log.Println("Aritu.Add")
	addCall := client.Go("Arith.Add", args, addReply, nil)

	addCall = <-addCall.Done
	if addCall.Error != nil {
		t.Errorf("Add: expected no error but got string %q", addCall.Error.Error())
	}
	if addReply.C != args.A+args.B {
		t.Errorf("Add: expected %d got %d", addReply.C, args.A+args.B)
	}

	mulCall = <-mulCall.Done
	if mulCall.Error != nil {
		t.Errorf("Mul: expected no error but got string %q", mulCall.Error.Error())
	}
	if mulReply.C != args.A*args.B {
		t.Errorf("Mul: expected %d got %d", mulReply.C, args.A*args.B)
	}

	//	// Error test
	//	args = &Args{7, 0}
	//	reply = new(Reply)
	//	err = client.Call("Arith.Div", args, reply)
	//	// expect an error: zero divide
	//	if err == nil {
	//		t.Error("Div: expected error")
	//	} else if err.Error() != "divide by zero" {
	//		t.Error("Div: expected divide by zero error; got", err)
	//	}
	//
	//	// Bad type.
	//	reply = new(Reply)
	//	err = client.Call("Arith.Add", reply, reply) // args, reply would be the correct thing to use
	//	if err == nil {
	//		t.Error("expected error calling Arith.Add with wrong arg type")
	//	} else if strings.Index(err.Error(), "type") < 0 {
	//		t.Error("expected error about type; got", err)
	//	}
	//
	//	// Non-struct argument
	//	const Val = 12345
	//	str := new(Str)
	//	str.Val = fmt.Sprint(Val)
	//	reply = new(Reply)
	//	err = client.Call("Arith.Scan", str, reply)
	//	if err != nil {
	//		t.Errorf("Scan: expected no error but got string %q", err.Error())
	//	} else if reply.C != Val {
	//		t.Errorf("Scan: expected %d got %d", Val, reply.C)
	//	}
	//
//.........这里部分代码省略.........
开发者ID:scabwort,项目名称:protorpc,代码行数:101,代码来源:server_test.go



注:本文中的github.com/Terry-Mao/protorpc.Dial函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang protorpc.Client类代码示例发布时间:2022-05-28
下一篇:
Golang rpc.MessageGetResp类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap