當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。