当前位置: 首页>>代码示例>>Golang>>正文


Golang protorpc.Dial函数代码示例

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


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


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