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


Golang rpc.Accept函数代码示例

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


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

示例1: init

// Initialise Server, registering RPC service and binding to port 1234
func (t *Server) init() {

	t.Status = true
	rpc.Register(t)
	tcpAddr, err := net.ResolveTCPAddr("tcp", ":1234")
	t.checkError(err)

	listener, err := net.ListenTCP("tcp", tcpAddr)
	t.checkError(err)

	// create new map for tracking routes
	t.Routes = make(map[int][]*Tram)
	t.Clients = make(map[string]*Record)

	rpc.Accept(listener)

	// case want to add additional socket accounting
	// for {
	// 	conn, err := listener.Accept()
	// 	if err != nil {
	// 		continue
	// 	}
	// 	rpc.ServeConn(conn)
	// }
}
开发者ID:vly,项目名称:go-rpc-example,代码行数:26,代码来源:server.go

示例2: main

func main() {
	flag.Parse()

	rpc.Register(new(Worker))
	l, e := net.Listen("tcp", ":"+strconv.Itoa(*port))
	if e != nil {
		log.Fatal("listen error:", e)
	}
	log.Print("listening for connections on ", l.Addr())

	if *connect != "" {
		log.Printf("calling %s\n", *connect)
		conn, err := net.Dial("tcp", *connect)
		if err != nil {
			log.Fatalf("failed to connect to %s: %s", *connect, err)
		}
		addr, _, err := net.SplitHostPort(conn.LocalAddr().String())
		if err != nil {
			log.Fatalf("failed to get the local address: %s", err)
		}
		laddr := net.JoinHostPort(addr, strconv.Itoa(*port))
		client := rpc.NewClient(conn)
		var res struct{}
		client.Call("WorkerList.Add", laddr, &res)
		client.Close()
	}

	rpc.Accept(l)
}
开发者ID:velour,项目名称:distribute,代码行数:29,代码来源:main.go

示例3: clusterInit

func clusterInit(configString json.RawMessage) {
	if globals.cluster != nil {
		log.Fatal("Cluster already initialized")
	}

	// This is a standalone server, not initializing
	if configString == nil || len(configString) == 0 {
		log.Println("Running as a standalone server.")
		return
	}

	var config ClusterConfig
	if err := json.Unmarshal(configString, &config); err != nil {
		log.Fatal(err)
	}

	globals.cluster = &Cluster{
		thisNodeName: config.ThisName,
		ring:         rh.New(CLUSTER_HASH_REPLICAS, nil),
		nodes:        make(map[string]*ClusterNode)}
	ringKeys := make([]string, 0, len(config.Nodes))

	for _, host := range config.Nodes {
		ringKeys = append(ringKeys, host.Name)

		if host.Name == globals.cluster.thisNodeName {
			// Don't create a cluster member for this local instance
			continue
		}

		n := ClusterNode{address: host.Addr, name: host.Name}
		n.done = make(chan bool, 1)
		go n.reconnect()

		globals.cluster.nodes[host.Name] = &n
	}

	if len(globals.cluster.nodes) == 0 {
		log.Fatal("Invalid cluster size: 0")
	}

	globals.cluster.ring.Add(ringKeys...)

	addr, err := net.ResolveTCPAddr("tcp", config.ListenOn)
	if err != nil {
		log.Fatal(err)
	}

	globals.cluster.inbound, err = net.ListenTCP("tcp", addr)
	if err != nil {
		log.Fatal(err)
	}

	rpc.Register(globals.cluster)
	go rpc.Accept(globals.cluster.inbound)

	log.Printf("Cluster of %d nodes initialized, node '%s' listening on [%s]", len(globals.cluster.nodes)+1,
		globals.cluster.thisNodeName, config.ListenOn)
}
开发者ID:ycaihua,项目名称:chat,代码行数:59,代码来源:cluster.go

示例4: StartServer

// StartServer starts the HTTP RPC server
func StartServer() {
	l, e := net.Listen("tcp", "0.0.0.0:1234") // FIXME get port from config file
	if e != nil {
		log.Fatal("listen error:", e)
	}

	// this serves endless
	rpc.Accept(l)
}
开发者ID:holgerBerger,项目名称:go_ludalo,代码行数:10,代码来源:lustreserver.go

示例5: StartServer

// StartServer runs the endless rpc server FIX TLS needed
func StartServer() {
	l, e := net.Listen("tcp", "0.0.0.0:"+port)
	if e != nil {
		log.Fatal("listen error:", e)
	}

	// this serves endless
	rpc.Accept(l)
}
开发者ID:holgerBerger,项目名称:pafimi,代码行数:10,代码来源:pafimi_server.go

示例6: start

// start of RPC server
func (rpcs *RPCServer) start(addr string) {
	listen, e := net.Listen("tcp", addr)
	if e != nil {
		log.Fatal("listen error:", e)
	}
	rpcs.listen = listen

	rpc.Accept(rpcs.listen)
}
开发者ID:saromanov,项目名称:lockwood,代码行数:10,代码来源:rpcserver.go

示例7: startRpc

func startRpc() net.Listener {
	lis, err := net.Listen("tcp", net.JoinHostPort("", strconv.Itoa(RpcPort)))
	if err != nil {
		log.Fatal("rpc.Start:", err)
	}

	go rpc.Accept(lis)
	return lis
}
开发者ID:jimenezrick,项目名称:debris,代码行数:9,代码来源:rpc.go

示例8: ServeRPC

func ServeRPC() {
	rpc.Register(NewRPC())
	rpc_on := fmt.Sprintf("%s:%d", config.BindAddress, config.RPCPort)
	l, e := net.Listen("tcp", rpc_on)
	if e != nil {
		log.Fatal("listen error:", e)
	}
	rpc.Accept(l)
}
开发者ID:sohailalam2,项目名称:redskull,代码行数:9,代码来源:rpcserver.go

示例9: startAdders

// StartAdders registers the jobadder and accepts
// incoming connections
func startAdders(joblist *joblist) {
	jobAdder := JobAdder{joblist}
	rpc.Register(&jobAdder)
	l, err := net.Listen("tcp", ":"+strconv.Itoa(*cmdport))
	if err != nil {
		logfile.Fatal("listen error:", err)
	}
	logfile.Print("listening for new commands on ", l.Addr())
	go rpc.Accept(l)
}
开发者ID:velour,项目名称:distribute,代码行数:12,代码来源:adder.go

示例10: main

func main() {
	rpc.Register(NewRPC())

	l, e := net.Listen("tcp", ":9876")
	if e != nil {
		log.Fatal("listen error:", e)
	}

	rpc.Accept(l)
}
开发者ID:prevoty,项目名称:rpc_tutorial,代码行数:10,代码来源:server.go

示例11: initCli

func initCli() *rpc.Client {
	l, err := net.Listen("tcp", ":11019")
	if err != nil {
		return nil
	}
	rpc.RegisterName("Math", new(Math))
	go rpc.Accept(l)
	cli, _ := rpc.Dial("tcp", ":11019")
	return cli
}
开发者ID:clrpc,项目名称:clrpc-go,代码行数:10,代码来源:rpc_test.go

示例12: main

func main() {
	fmt.Println("Starting up RPC server...")
	server := paperclips.NewRPCServer()
	rpc.Register(server)
	fmt.Println("Now listening on", address)
	l, e := net.Listen("tcp", address)
	if e != nil {
		log.Fatal("listen error:", e)
	}
	rpc.Accept(l)
}
开发者ID:orborde,项目名称:paperclips,代码行数:11,代码来源:server_main.go

示例13: main

func main() {
	rpc.Register(rpctime.NewRPC()) // HL

	l, err := net.Listen("tcp", ":19876") // HL
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}

	rpc.Accept(l) // HL
}
开发者ID:euggo,项目名称:meetup,代码行数:11,代码来源:main.go

示例14: main

func main() {
	gobby := new(Gobby)
	rpc.Register(gobby)
	l, e := net.Listen("tcp", ":1234")
	if e != nil {
		log.Fatal("listen error:", e)
	}
	go rpc.Accept(l)
	go rawProtocol_refl()
	rawProtocol_hand()
}
开发者ID:u20024804,项目名称:Scraps,代码行数:11,代码来源:Server.go

示例15: startServer

// StartServer starts the HTTP RPC server
func startServer() {
	server := new(ServerRpcT)
	rpc.Register(server)
	l, e := net.Listen("tcp", "localhost:2345") // FIXME get port from config file
	if e != nil {
		log.Fatal("listen error:", e)
	}

	// this serves endless
	rpc.Accept(l)
}
开发者ID:holgerBerger,项目名称:go_ludalo,代码行数:12,代码来源:rpcserver.go


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