Ejemplo n.º 1
0
//----------------------------------------------- HUB start
func HubStart() {
	// start logger
	config := cfg.Get()
	if config["hub_log"] != "" {
		cfg.StartLogger(config["hub_log"])
	}

	log.Println("Starting HUB")
	startup_work()
	go SignalProc()

	// Listen
	service := DEFAULT_SERVICE
	if config["hub_service"] != "" {
		service = config["hub_service"]
	}

	log.Println("Hub Service:", service)
	tcpAddr, err := net.ResolveTCPAddr("tcp4", service)
	checkError(err)

	listener, err := net.ListenTCP("tcp", tcpAddr)
	checkError(err)

	log.Println("HUB Server OK.")
	for {
		conn, err := listener.AcceptTCP()
		if err != nil {
			continue
		}
		helper.SetConnParam(conn)
		go handleClient(conn)
	}
}
Ejemplo n.º 2
0
//---------------------------------------------------------- Event Server start
func EventStart() {
	config := cfg.Get()
	if config["profile"] == "true" {
		helper.SetMemProfileRate(1)
		defer func() {
			helper.GC()
			helper.DumpHeap()
			helper.PrintGCSummary()
		}()
	}

	// start logger
	if config["event_log"] != "" {
		cfg.StartLogger(config["event_log"])
	}

	log.Println("Starting Event Server")
	startup_work()
	go SignalProc()

	// Listen
	service := DEFAULT_SERVICE
	if config["event_service"] != "" {
		service = config["event_service"]
	}

	log.Println("Event Service:", service)
	tcpAddr, err := net.ResolveTCPAddr("tcp4", service)
	checkError(err)

	listener, err := net.ListenTCP("tcp", tcpAddr)
	checkError(err)

	log.Println("Event Server OK.")
	for {
		conn, err := listener.AcceptTCP()
		if err != nil {
			continue
		}
		helper.SetConnParam(conn)
		go handleClient(conn)
	}
}
Ejemplo n.º 3
0
//----------------------------------------------- connect to Event server
func DialEvent() {
	log.Println("Connecting to Event server")
	config := cfg.Get()

	addr, err := net.ResolveTCPAddr("tcp", config["event_service"])
	if err != nil {
		log.Println(err)
		os.Exit(-1)
	}

	conn, err := net.DialTCP("tcp", nil, addr)
	if err != nil {
		log.Println(err)
		os.Exit(-1)
	}

	helper.SetConnParam(conn)
	_conn = conn

	log.Println("Event Service Connected")
	go EventReceiver(conn)
}
Ejemplo n.º 4
0
//----------------------------------------------- connect to hub
func DialHub() {
	log.Println("Connecting to HUB")
	config := cfg.Get()

	addr, err := net.ResolveTCPAddr("tcp", config["hub_service"])
	if err != nil {
		log.Println(err)
		os.Exit(-1)
	}

	conn, err := net.DialTCP("tcp", nil, addr)
	if err != nil {
		log.Println(err)
		os.Exit(-1)
	}

	helper.SetConnParam(conn)
	_conn = conn

	log.Println("HUB connected")
	go HubReceiver(conn)
}