Ejemplo n.º 1
0
func NewCoRpcServer() *CoRpcServer {
	ctx := context.GetContext()

	coRpcS, ok := ctx.GetComponent("corpcserver").(*CoRpcServer)
	if ok == true {
		return coRpcS
	}

	host, _ := ctx.CurrentServer["host"].(string)
	port, _ := ctx.CurrentServer["port"].(int)
	rpcS := rpcserver.NewRpcServer(host, port)

	coRpcS = &CoRpcServer{rpcS}
	ctx.RegisteComponent("corpcserver", coRpcS)
	seelog.Info("CoRpcServer create successfully")
	return coRpcS
}
Ejemplo n.º 2
0
func main() {
	if len(os.Args) != 3 {
		log.Fatal("too few args to server,commandline form <command host port>")
	}

	context.NewContext()
	host := os.Args[1]
	port, err := strconv.Atoi(os.Args[2])
	if err != nil {
		log.Fatalf("Fail to convert os.args[2] to port(type int),error message:", err.Error())
	}

	server := rpcserver.NewRpcServer(host, port)
	server.RegisteService(new(Echo))

	server.Start()
}