Exemple #1
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	c, err := goconfig.LoadConfigFile("conf/conf.ini")
	if err != nil {
		log.Fatal(err)
	}

	HTTP_PORT, err = c.GetValue("Server", "port")
	checkError(err)

	// creates a tcp listener
	tcpAddr, err := net.ResolveTCPAddr("tcp4", ":"+HTTP_PORT)
	checkError(err)
	listener, err := net.ListenTCP("tcp", tcpAddr)
	checkError(err)

	sendChan, err := c.Int("Server", "sendChan")
	checkError(err)
	receiveChan, err := c.Int("Server", "receiveChan")
	checkError(err)

	// creates a server
	config := &gametcp.Config{
		PacketSendChanLimit:    uint32(sendChan),
		PacketReceiveChanLimit: uint32(receiveChan),
	}
	srv := gametcp.NewServer(config, &Callback{})

	// starts service
	go srv.Start(listener, time.Second*5)
	alog.Info("listening:" + listener.Addr().String())

	// catchs system signal
	chSig := make(chan os.Signal)
	signal.Notify(chSig, syscall.SIGINT, syscall.SIGTERM)
	sig := <-chSig
	alog.Error("listening:" + sig.String())

	// stops service
	srv.Stop()
}
Exemple #2
0
func checkError(err error) {
	if err != nil {
		alog.Error(err.Error())
	}
}