func (this *RunWithSnode) Init() error {
	config := config.NewConfig()
	config.Read("conf/push-server.conf")
	flag, err := config.GetInt("RunWithSnode")
	if err != nil {
		fmt.Println("Error in RunWithSnode.Init() ", err)
		return err
	}
	if flag == 0 {
		this.Flag = false
	} else {
		this.Flag = true
	}
	return nil
}
示例#2
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	config := config.NewConfig()

	err := config.Read("conf/Server.conf")
	if err != nil {
		fmt.Println("td-server Read conf file error")
		return
	}

	var IP string
	var TokenPort int
	var DispatchPort int

	IP, err = config.GetString("DispacthIP")
	if err != nil {
		fmt.Println("td-server Get IP error")
		return
	}
	TokenPort, err = config.GetInt("TokenPort")
	if err != nil {
		fmt.Println("td-server Get TokenPort error")
		return
	}
	DispatchPort, err = config.GetInt("DispatchPort")
	if err != nil {
		fmt.Println("td-server Get DispatchPort error")
		return
	}

	tokens := model.NewTokens()
	relations := model.NewRelations()

	tokenServer := dispatcher.NewTokener(IP, TokenPort, tokens)
	go tokenServer.Start()

	dispatchServer := dispatcher.NewDispatcher(IP, DispatchPort, tokens, relations)
	dispatchServer.Start()
}
示例#3
0
func (this *NodeComponent) ConfInit() error {
	var err error
	config := config.NewConfig()

	err = config.Read("conf/node.conf")
	if err != nil {
		fmt.Println("NodeComponent Error: read conf file error")
		return errors.New("NodeComponent Error:ConfInit")
	}
	//conf里没有
	this.StreeID, err = config.GetString("StreeID")
	if err != nil {
		fmt.Println("NodeComponent Error:Parse StreeID")
		return errors.New("NodeComponent Error: StreeID")
	}
	//MainStreeIP:10.0.0.7
	this.MainStreeIP, err = config.GetString("MainStreeIP")
	if err != nil {
		fmt.Println("NodeComponent Error:Parse MainStreeIP")
		return errors.New("NodeComponent Error: ConfInit")
	}
	//MainStreePort:10000
	this.MainStreePort, err = config.GetInt("MainStreePort")
	if err != nil {
		fmt.Println("NodeComponent Error:Parse MainStreePort")
		return errors.New("NodeComponent Error: ConfInit")
	}
	//SpareStreeIP:10.0.0.7
	this.SpareStreeIP, err = config.GetString("SpareStreeIP")
	if err != nil {
		fmt.Println("NodeComponent Error:Parse SpareStreePort")
		return errors.New("NodeComponent Error: ConfInit")
	}
	//SpareStreePort:10001
	this.SpareStreePort, err = config.GetInt("SpareStreePort")
	if err != nil {
		fmt.Println("NodeComponent Error: Parse SpareStreePort")
		return errors.New("NodeComponent Error: ConfInit")
	}
	//conf里无,HeartBeatTime = 1
	this.HeartBeatTime, err = config.GetInt("HeartBeatTime")
	if err != nil {
		fmt.Println("NodeComponent Error: Parse HeartBeatTime, Use Heart Beat Time Default Value 1")
		this.HeartBeatTime = 1
	}
	//conf里无,CacheSize = 10000
	this.CacheSize, err = config.GetInt("CacheSize")
	if err != nil {
		fmt.Println("NodeComponent Error: Parse CacheSize, Use Cache Size Default Value 10000")
		this.CacheSize = 10000
	}
	//conf里无,ReconnectTime = 1
	this.ReConnectTime, err = config.GetInt("ReConnectTime")
	if err != nil {
		fmt.Println("NodeComponent Error: Parse ReConnectTime, Use ReConnectTime Default Value 1")
		this.ReConnectTime = 1
	}
	//conf里无,GOMAXPROCS为当前最大CPU数
	this.GOMAXPROCS, err = config.GetInt("GOMAXPROCS")
	if err != nil {
		fmt.Println("NodeComponent Error: Parse GOMAXPROCS, Use GOMAXPROCS Default Value 8")
		this.GOMAXPROCS = runtime.NumCPU()
	}

	runtime.GOMAXPROCS(this.GOMAXPROCS)
	return nil
}
示例#4
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	config := config.NewConfig()

	err := config.Read("conf/server.conf")
	if err != nil {
		err = fmt.Errorf("Main Error: %v", err)
		fmt.Println(err.Error())
		return
	}
	var IP string
	var Port int
	var UDPPort int
	var DispatchIP string
	var TokenPort int

	IP, err = config.GetString("ServerIP")
	if err != nil {
		err = fmt.Errorf("Main Error: %v", err)
		fmt.Println(err.Error())
		return
	}

	Port, err = config.GetInt("ServerPort")
	if err != nil {
		err = fmt.Errorf("Main Error: %v", err)
		fmt.Println(err.Error())
		return
	}

	UDPPort, err = config.GetInt("UDPServerPort")
	if err != nil {
		err = fmt.Errorf("Main Error: %v", err)
		fmt.Println(err.Error())
		return
	}

	DispatchIP, err = config.GetString("DispatchIP")
	if err != nil {
		err = fmt.Errorf("Main Error: %v", err)
		fmt.Println(err.Error())
		return
	}

	TokenPort, err = config.GetInt("TokenPort")
	if err != nil {
		err = fmt.Errorf("Main Error: %v", err)
		fmt.Println(err.Error())
		return
	}

	userCache := model.NewUserCache()
	udpServer := qserver.NewUDPServer(IP, UDPPort, userCache)
	if udpServer == nil {
		fmt.Println("Start UDPServer error")
		return
	}
	go udpServer.Start()

	tcpServer := qserver.NewQServer(IP, Port, userCache, DispatchIP, TokenPort)
	tcpServer.Start()

}
示例#5
0
func main() {

	runtime.GOMAXPROCS(runtime.NumCPU())

	config := config.NewConfig()

	err := config.Read("conf/uds.conf")
	if err != nil {
		fmt.Println("read conf file error")
	}

	var IP string
	var Port int
	var TCPPort int
	var RegisterResponseCount int
	var BuffLength int

	IP, err = config.GetString("IP")
	if err != nil {
		fmt.Println("parse  IP error")
		return
	}

	Port, err = config.GetInt("Port")
	if err != nil {
		fmt.Println("parse Port error")
		return
	}

	TCPPort, err = config.GetInt("TCPPort")
	if err != nil {
		fmt.Println("parse TCPPort error")
		return
	}
	fmt.Println(TCPPort)

	RegisterResponseCount, err = config.GetInt("RegisterResponseCount")
	if err != nil {
		fmt.Println("Err - parse RegisterResponseCount, set default value 10")
		RegisterResponseCount = 10
	}

	BuffLength, err = config.GetInt("BuffLength")
	if err != nil {
		fmt.Println("Err - parse BuffLength, set default value 100000")
		BuffLength = 100000
	}

	send := component.GetSendComponent()
	send.Init(BuffLength)
	send.Start()

	register := component.GetRegisterComponent()
	register.Init(RegisterResponseCount, BuffLength)
	register.Start()

	deleteComponent := component.GetDeleteComponent()
	deleteComponent.Init(BuffLength)
	deleteComponent.Start()

	tcp := component.GetTcpComponent()
	tcp.Init(IP, uint16(TCPPort))
	tcp.Start()

	receive := component.GetReceiveComponent()
	receive.Init(IP, uint16(Port))
	receive.Start()
}