Exemplo n.º 1
0
func main() {
	fmt.Println("XMAN Test")

	// argv: name default_val introduction
	configFile := flag.String("conf", "./config/srv.ini", "server config file.")
	flag.Parse()

	fmt.Println(*configFile)
	config := InitConfig(*configFile)
	section, err := config.Section("MysqlInfo")
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(section.ValueOf("host"))

	test := &xmandemo.BaseHeader{
		Ver: proto.Uint32(111),
		Bus: proto.Uint32(222),
		Seq: proto.Uint32(1),
		Cmd: proto.Uint32(uint32(xmandemo.XCMD_CMD_DEMO)),
	}
	data, err := proto.Marshal(test)
	fmt.Println(data)

	//	utils.Daemonize(0, 1)

	SetConsoleShow(true)
	//	SetRollingDaily("/Users/reezhou/Desktop/xman/src/logs", "test.log")
	SetRollingFile("/Users/reezhou/Desktop/xman/src/logs", "rolling.log", 10, 50, MB)
	SetLogLevel(LOG_DEBUG)
	//	Log(LOG_ERROR, "uin error")

	// redis test
	//	redisController = xmandb.NewRedisController()
	//	defer redisController.Close()
	//	err = redisController.InitRedis("", ":6379", 0)
	//	if err != nil {
	//		fmt.Println("redis init error.",err)
	//	}
	//	v, _ := redis.String(redisController.Get("ree"), err)
	//	fmt.Println("get from redis: ", v)
	//
	//	// mysql test
	//	mysqlController = xmandb.NewMysqlController()
	//	err = mysqlController.InitMysql(`{"user": "******", "password": "******", "address": ":3306", "dbname": "xman"}`)
	//	defer mysqlController.Close()
	//	if err != nil {
	//		fmt.Println(err)
	//	}
	//	row, _ := mysqlController.FetchRows("SELECT * FROM user")
	//	fmt.Println(row)

	goServer(config)
}
Exemplo n.º 2
0
func main() {
	fmt.Println("XMAN Test")
	config, err := xmanconfig.Read("/Users/reezhou/Desktop/xman/src/config/srv.ini")
	if err != nil {
		fmt.Println(err)
		return
	}
	section, err := config.Section("MysqlInfo")
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(section.ValueOf("host"))

	SetConsoleShow(true)
	//	SetRollingDaily("/Users/reezhou/Desktop/xman/src/logs", "test.log")
	SetRollingFile("/Users/reezhou/Desktop/xman/src/logs", "rolling.log", 10, 50, MB)
	SetLogLevel(LOG_DEBUG)
	//	Log(LOG_ERROR, "uin error")

	// RegisterUDPServer maybe need before RegisterUDPConn
	// Prevent port is occupied
	//	RegisterUDPServer(UDPTESTSRV, ":6001")
	// Run server loop
	//	RunUDPServer(UDPTESTSRV, &SrvProcessLogic{})

	// TCP Server
	tcpServer, err := RegisterTCPServer("tcp", ":7001", xmandemo.UnpackTCP, RemoteTCPLogicHandler, MaxReqChanLen)
	if err != nil {
		Log(LOG_ERROR, "tcp server listen err.", err)
		return
	}
	defer tcpServer.Close()

	tcpServer.AcceptLoop()
}