示例#1
0
// 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)
	// }
}
示例#2
0
文件: main.go 项目: velour/distribute
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)
}
示例#3
0
文件: cluster.go 项目: ycaihua/chat
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)
}
示例#4
0
// 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)
}
示例#5
0
// 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)
}
示例#6
0
// 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)
}
示例#7
0
文件: rpc.go 项目: jimenezrick/debris
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
}
示例#8
0
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)
}
示例#9
0
// 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)
}
示例#10
0
func (rpcdata *RPCData) Run() {
	go func() {
		l, e := net.Listen("tcp", rpcdata.address)
		if e != nil {
			log.Fatal("listen error:", e)
		}

		rpc.Accept(l)
	}()
}
示例#11
0
func main() {
	rpc.Register(NewRPC())

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

	rpc.Accept(l)
}
示例#12
0
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
}
示例#13
0
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)
}
示例#14
0
文件: main.go 项目: euggo/meetup
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
}
示例#15
0
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()
}
示例#16
0
// 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)
}
示例#17
0
func (s *Client) Serve() error {
	rpc.Register(&GossipCore{s})

	l, err := net.Listen("tcp", s.Address)
	if err != nil {
		return err
	}

	go rpc.Accept(l)

	return nil
}
示例#18
0
func DealWithRPC(server RPCServer, rpc_addr string) {
	addr, err := net.ResolveTCPAddr("tcp", rpc_addr)
	if err != nil {
		panic(err)
	}
	inbound, err := net.ListenTCP("tcp", addr)
	if err != nil {
		panic(err)
	}
	rpc.Register(server)
	rpc.Accept(inbound)
}
示例#19
0
// StartRemoteMasterServer starts a remote APM server listening on dsn address and binding to
// configFile.
// It returns a RemoteMaster instance.
func StartRemoteMasterServer(dsn string, configFile string) *RemoteMaster {
	remoteMaster := &RemoteMaster{
		master: InitMaster(configFile),
	}
	rpc.Register(remoteMaster)
	l, e := net.Listen("tcp", dsn)
	if e != nil {
		log.Fatal("listen error: ", e)
	}
	go rpc.Accept(l)
	return remoteMaster
}
示例#20
0
func (k *Kademlia) Serve() error {
	rpc.Register(&KademliaCore{k})

	l, err := net.Listen("tcp", k.routes.self.Address)
	if err != nil {
		return err
	}

	go rpc.Accept(l)

	return nil
}
示例#21
0
// Serve starts the RPC server on listener. Serve blocks.
func Serve(listener net.Listener, dbmap *gorp.DbMap) error {
	dbmap.AddTable(UniVar{}).SetKeys(false, "Name")
	err := dbmap.CreateTablesIfNotExists()
	if err != nil {
		return err
	}

	server := &Elvishd{dbmap}
	rpc.Register(server)
	rpc.Accept(listener)
	return nil
}
示例#22
0
文件: main.go 项目: pepol/forge
func main() {

	port_flag := flag.Int("port", PORT_DEFAULT, "Specify port number to listen on.")
	root_flag := flag.String("root", "",
		"Specify root working directory for Forge.")
	jobs_flag := flag.Int("jobs", runtime.NumCPU(),
		"Specify number of jobs to run simultaneously.")
	flag.Parse()

	var port int
	port = PORT_DEFAULT
	if *port_flag > 0 && *port_flag < 65535 {
		port = *port_flag
	}

	var jobs int
	jobs = runtime.NumCPU()
	if *jobs_flag > 0 {
		jobs = *jobs_flag
	}

	runtime.GOMAXPROCS(jobs)

	var forge_root *string = new(string)
	*forge_root = ROOT_DEFAULT
	root_env := os.Getenv("FORGE_ROOT")
	if root_env != "" {
		forge_root = &root_env
	}
	if *root_flag != "" {
		forge_root = root_flag
	}

	sem := make(chan int, jobs)
	config := tasks.Config{Root: *forge_root}

	task := tasks.Task{Semaphore: sem, Config: &config}
	file := files.File{Rootdir: *forge_root}
	util := util.Util{Jobs: jobs}
	rpc.Register(&task)
	rpc.Register(&file)
	rpc.Register(&util)

	port_spec := fmt.Sprintf(":%d", port)

	tcp_addr, err := net.ResolveTCPAddr("tcp", port_spec)
	checkError(err)
	listener, err := net.ListenTCP("tcp", tcp_addr)
	checkError(err)

	rpc.Accept(listener)
}
示例#23
0
func rpcListen(bind string) {
	l, err := net.Listen("tcp", bind)
	if err != nil {
		glog.Errorf("net.Listen(\"tcp\", \"%s\") error(%v)", bind, err)
		panic(err)
	}
	defer func() {
		if err := l.Close(); err != nil {
			glog.Errorf("listener.Close() error(%v)", err)
		}
	}()
	rpc.Accept(l)
}
示例#24
0
func startWorkers(joblist *joblist) {
	rpc.Register(&WorkerList{joblist})
	l, err := net.Listen("tcp", ":"+strconv.Itoa(*port))
	if err != nil {
		logfile.Fatal("listen error:", err)
	}
	logfile.Print("listening for new workers on ", l.Addr())
	go rpc.Accept(l)

	for _, addr := range flag.Args() {
		go worker(addr, joblist)
	}
}
示例#25
0
文件: rpc.go 项目: dvyukov/goperfd
func benchmark() driver.Result {
	if rpcServerAddr == "" {
		rpc.Register(new(Server))
		rpc.RegisterName("Server", new(Server))
		l, err := net.Listen("tcp", "127.0.0.1:0")
		if err != nil {
			log.Fatalf("net.Listen tcp :0: %v", err)
		}
		rpcServerAddr = l.Addr().String()
		go rpc.Accept(l)
	}
	return driver.Benchmark(benchmarkN)
}
示例#26
0
func main() {

	var pathMakefile, target, address string
	var displayHelp bool

	flag.BoolVar(&displayHelp, "help", false, "Display help")
	flag.StringVar(&pathMakefile, "makefile", "Makefile", "Path to the Makefile")
	flag.StringVar(&target, "target", "out.avi", "Target to execute")
	flag.StringVar(&address, "address", "localhost:9876", "address to listen")
	flag.Parse()

	if displayHelp {
		flag.PrintDefaults()
		return
	}

	//Test si le fichier Makefile existe bien
	if _, err := os.Stat(pathMakefile); os.IsNotExist(err) {
		log.Fatal("Makefile not found :", pathMakefile)
	}

	//Parse le makefile et récupère la règle root
	log.Println("Makefile parsing Start")
	listRules := parsing.Makefile(pathMakefile, target)
	log.Println("Makefile parsing Done")

	//On initialise nos jobs qui vont distribuer les règles aux slaves
	j := job.NewJob(listRules, target)

	//On lance la recherche des règles éligibles en background
	go findTargets(listRules[target], j)

	//Setup du serveur
	log.Println("Start server on address:", address)

	rpc.Register(j)
	l, err := net.Listen("tcp", address)
	if err != nil {
		log.Fatal("listen error:", err)
	}

	go rpc.Accept(l)

	log.Println("Ready to accept new connection")

	//Attend le signal que toutes les targets soient faites
	<-j.Done

	l.Close()
	log.Println("Server shuting down")
}
示例#27
0
文件: main.go 项目: 0x7cc/rsc
func serve() {
	f, err := os.OpenFile(google.Dir()+"/log", os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0600)
	if err != nil {
		log.Fatal(err)
	}
	log.SetOutput(f)
	syscall.Dup2(f.Fd(), 2)
	os.Stdout = f
	os.Stderr = f
	l := listen()
	rpc.RegisterName("goog", &Server{})
	rpc.Accept(l)
	log.Fatal("rpc.Accept finished: server exiting")
}
示例#28
0
文件: rpc.go 项目: Crysty-Yui/goim
func rpcListen(network, addr string) {
	l, err := net.Listen(network, addr)
	if err != nil {
		log.Error("net.Listen(\"%s\", \"%s\") error(%v)", network, addr, err)
		panic(err)
	}
	// if process exit, then close the rpc addr
	defer func() {
		log.Info("listen rpc: \"%s\" close", addr)
		if err := l.Close(); err != nil {
			log.Error("listener.Close() error(%v)", err)
		}
	}()
	rpc.Accept(l)
}
示例#29
0
func rpcListen(bind string) {
	l, err := net.Listen("tcp", bind)
	if err != nil {
		Log.Error("net.Listen(\"tcp\", \"%s\") error(%v)", bind, err)
		panic(err)
	}
	// if process exit, then close the rpc bind
	defer func() {
		Log.Info("rpc addr: \"%s\" close", bind)
		if err := l.Close(); err != nil {
			Log.Error("listener.Close() error(%v)", err)
		}
	}()
	rpc.Accept(l)
}
示例#30
0
func main() {
	addy, err := net.ResolveTCPAddr("tcp", ":42586")
	if err != nil {
		log.Fatal(err)
	}

	inbound, err := net.ListenTCP("tcp", addy)
	if err != nil {
		log.Fatal(err)
	}

	listener := new(Listener)
	rpc.Register(listener)
	rpc.Accept(inbound)
}