Exemplo n.º 1
0
// Start up the RPC Server
func server(registry *Registry, port int) error {
	rpc.Register(registry)
	rpc.HandleHTTP()
	ln, err := net.Listen("tcp", util.Address("", port))
	if err != nil {
		return err
	}
	go func() {
		for {
			conn, _ := ln.Accept()
			rpc.ServeCodec(jsonrpc.NewServerCodec(conn))
		}
	}()
	return nil
}
Exemplo n.º 2
0
func Start(name string, hostname string, seeds []string, port int) (chan []byte, error) {
	address := util.Address(hostname, port)
	registry = NewRegistry(name)
	registry.Self = &Node{Name: name, Address: address}

	var err error

	err = server(registry, port)
	if err != nil {
		return nil, err
	}

	err = client(registry, seeds, port)
	if err != nil {
		return nil, err
	}

	return registry.Data, nil
}