Exemple #1
0
func main() {

	fmt.Println("main")
	var s1 = []int{1, 2, 3, 4, 5}
	//var s2 = s1

	fn1(&s1)
	fmt.Println(s1)
	//fmt.Println(s2)
	fmt.Println("OK")
	//	var ss []byte
	//	for {
	//		time.Sleep(1 * time.Second)
	//		fmt.Println("OK")
	//		ss = make([]byte, 1024*1024*100)
	//		fmt.Println(ss[0:1])
	//	}

	////////////////////////////////////////////////////////////////////
	rand.Seed(time.Now().Unix())

	ret := initPbFun()
	if zzcommon.SUCC != ret {
		fmt.Println("######initPbFun")
		return
	}

	fmt.Println("server runing...", time.Now())

	///////////////////////////////////////////////////////////////////
	//测试
	///////////////////////////////////////////////////////////////////

	///////////////////////////////////////////////////////////////////
	//加载配置文件bench.ini
	{
		if zzcommon.IsWindows() {
			ict_cfg.Gbench.Load("./bench.ini.bak")
		} else {
			ict_cfg.Gbench.Load("/Users/mlc/Desktop/GoServer/icartravel/bench.ini.bak")
		}
		//		fmt.Println("######~~~~~~")
		//		fmt.Println(ict_cfg.Gbench.FileIni)
	}

	//////////////////////////////////////////////////////////////////
	//redis
	{
		const benchFileSection string = "redis_server"
		ip := ict_cfg.Gbench.FileIni.Get(benchFileSection, "ip", " ")
		port := zzcommon.StringToUint16(ict_cfg.Gbench.FileIni.Get(benchFileSection, "port", " "))
		redisDatabases := zzcommon.StringToInt(ict_cfg.Gbench.FileIni.Get(benchFileSection, "databases", " "))

		//链接redis
		err := ict_common.GRedisClient.Connect(ip, port, redisDatabases)
		if nil != err {
			fmt.Println("######ict_common.GRedisClient.Connect(ip, port, redisDatabases) err:", err)
			return
		}
	}

	//////////////////////////////////////////////////////////////////
	//作为HTTP SERVER
	{
		//phome sms
		{
			err := ict_phone_sms.GphoneSms.Init()
			if nil != err {
				fmt.Println("######ict_phone_sms.GphoneSms.Init()")
				return
			}
		}

		gHttpServer.AddHandler(weatherPattern, WeatherHttpHandler)
		gHttpServer.AddHandler(ict_login.LoginPattern, ict_login.LoginHttpHandler)

		//启动手机注册功能
		{
			err := ict_account.GphoneSmsRegister.Init()
			if nil != err {
				fmt.Println("错误ict_account.GphoneSmsRegister.Init()")
				return
			}
			gHttpServer.AddHandler(ict_account.GphoneSmsRegister.Pattern, ict_account.PhoneSmsRegisterHttpHandler)

			err = ict_account.GphoneSmsChangePwd.Init()
			if nil != err {
				fmt.Println("错误ict_account.GphoneSmsChangePwd.Init()")
				return
			}
			gHttpServer.AddHandler(ict_account.GphoneSmsChangePwd.Pattern, ict_account.PhoneSmsChangePwdHttpHandler)

			err = ict_account.GphoneChangePwd.Init()
			if nil != err {
				fmt.Println("错误ict_account.GphoneChangePwd.Init()")
				return
			}
			gHttpServer.AddHandler(ict_account.GphoneChangePwd.Pattern, ict_account.PhoneChangePwdHttpHandler)

			err = ict_account.GphoneRegister.Init()
			if nil != err {
				fmt.Println("错误ict_account.GphoneRegister.Init()")
				return
			}
			gHttpServer.AddHandler(ict_account.GphoneRegister.Pattern, ict_account.PhoneRegisterHttpHandler)

			err = ict_user.Gbase.Init()
			if nil != err {
				fmt.Println("错误ict_user.Gbase.Init()")
				return
			}

			err = ict_user.GuidMgr.Init()
			if nil != err {
				fmt.Println("错误ict_user.GuidMgr.Init()")
				return
			}

			err = ict_login.Glogin.Init()
			if nil != err {
				fmt.Println("错误ict_login.Glogin.Init()")
				return
			}
		}

		ip := ict_cfg.Gbench.FileIni.Get("http_server", "ip", "999")
		port := zzcommon.StringToUint16(ict_cfg.Gbench.FileIni.Get("http_server", "port", "0"))

		go gHttpServer.Run(ip, port)
	}

	//////////////////////////////////////////////////////////////////
	//做为服务端
	{ //设置回调函数
		gTcpServer.OnInit = onInit
		gTcpServer.OnFini = onFini
		gTcpServer.OnCliConnClosed = onCliConnClosed
		gTcpServer.OnCliConn = onCliConn
		gTcpServer.OnCliGetPacketLen = onCliGetPacketLen
		gTcpServer.OnCliPacket = onCliPacket

		//运行
		noDelay := true
		ip := ict_cfg.Gbench.FileIni.Get("server", "ip", "")
		port := zzcommon.StringToUint16(ict_cfg.Gbench.FileIni.Get("server", "port", "0"))
		gTcpServer.PacketLengthMax = zzcommon.StringToUint32(ict_cfg.Gbench.FileIni.Get("common", "packet_length_max", "81920"))
		str_num_cpu := strconv.Itoa(runtime.NumCPU())
		goProcessMax := zzcommon.StringToInt(ict_cfg.Gbench.FileIni.Get("common", "go_process_max", str_num_cpu))
		runtime.GOMAXPROCS(goProcessMax)
		go gTcpServer.Run(ip, port, noDelay)
	}

	//////////////////////////////////////////////////////////////////
	//作为HTTP CLIENT Weather
	url := ict_cfg.Gbench.FileIni.Get("weather", "url", " ")
	gHttpClientWeather.Get(url)

	//////////////////////////////////////////////////////////////////
	//定时器
	zztimer.Second(1, timerSecondTest)
	fmt.Println("OK")
	for {
		time.Sleep(10 * time.Second)
		gLock.Lock()
		gLock.Unlock()
	}
	//////////////////////////////////////////////////////////////////
	//做为客户端
	{
		var gzztcpClient zztcp.Client_t
		gzztcpClient.OnSerConn = onSerConn
		gzztcpClient.OnSerConnClosed = onSerConnClosed
		gzztcpClient.OnSerGetPacketLen = onSerGetPacketLen
		gzztcpClient.OnSerPacket = onSerPacket

		ip := ict_cfg.Gbench.FileIni.Get("game_server", "ip", "999")
		port := zzcommon.StringToUint16(ict_cfg.Gbench.FileIni.Get("game_server", "port", "0"))
		packetLengthMax := zzcommon.StringToInt(ict_cfg.Gbench.FileIni.Get("game_server", "packet_length_max", "81920"))
		err := gzztcpClient.Connect(ip, port, packetLengthMax)
		if nil != err {
			fmt.Println("######zzcliClient.Connect err:", err)
		} else {
		}
	}

	///////////////////////////////////////////////////////////////////
	//测试chan
	/*
		ch := make(chan int, 0)
		end := make(chan int, 0)
		go func(ch chan int) {
			//		time.Sleep(1000000000 * 100)
			ch <- 1
			//		time.Sleep(1000000000 * 10)
			ch <- 2
		}(ch)
		var ii int
		var jj int
		//L:
		for {
			select {
			case <-ch:
				ii++
				fmt.Println("iiiiii", ii)
				if ii >= 2 {
					//				break L
				}
			case <-end:
				jj = 100
				fmt.Println("jjjjjj", jj)
			}
		}
		var ti uint32
		for {
			ti = ti + 1
			time.Sleep(1000000000)
			//		fmt.Println("===", i)
			//		fmt.Println("end")
		}
	*/
	//////////////////////////////////////////////////////////////////

	fmt.Println("!!!!!!server done!")
}
Exemple #2
0
func main() {
	fmt.Println("client runing...", time.Now())

	///////////////////////////////////////////////////////////////////
	//测试
	///////////////////////////////////////////////////////////////////

	///////////////////////////////////////////////////////////////////
	//加载配置文件bench.ini
	{
		if zzcommon.IsWindows() {
			ict_cfg.Gbench.Load("./bench.ini.bak")
		} else {
			ict_cfg.Gbench.Load("/Users/mlc/Desktop/GoServer/icartravel/bench.ini.bak")
		}
	}

	//////////////////////////////////////////////////////////////////
	//做为客户端
	{
		var gzztcpClient zztcp.Client_t
		gzztcpClient.OnSerConn = onSerConn
		gzztcpClient.OnSerConnClosed = onSerConnClosed
		gzztcpClient.OnSerGetPacketLen = onSerGetPacketLen
		gzztcpClient.OnSerPacket = onSerPacket

		ip := ict_cfg.Gbench.FileIni.Get("square_server", "ip", "999")
		port := zzcommon.StringToUint16(ict_cfg.Gbench.FileIni.Get("square_server", "port", "0"))
		packetLengthMax := zzcommon.StringToInt(ict_cfg.Gbench.FileIni.Get("square_server", "packet_length_max", "81920"))
		err := gzztcpClient.Connect(ip, port, packetLengthMax)
		if nil != err {
			fmt.Println("######zzcliClient.Connect err:", err)
			return
		}

		//发送pb测试包
		//登录
		{
			req := &pb_square.LoginMsg{
				Account:  proto.String("17721027200"),
				Password: proto.String("7883df2788b1098886f99b0a7563a5a8"),
			}
			fmt.Println(111)
			gzztcpClient.PeerConn.Send(req, 0x100101, 0, 0, 0)
		}
		//登录
		{
			req := &pb_square.LoginMsg{
				Account:  proto.String("17721027200"),
				Password: proto.String("7883df2788b1098886f99b0a7563a5a8"),
			}
			fmt.Println(222)
			gzztcpClient.PeerConn.Send(req, 0x100101, 0, 0, 0)
		}
	}

	//////////////////////////////////////////////////////////////////
	//定时器
	zztimer.Second(1, timerSecondTest)
	fmt.Println("OK")
	for {
		time.Sleep(10 * time.Second)
		gLock.Lock()
		gLock.Unlock()
	}

	///////////////////////////////////////////////////////////////////
	//测试chan
	/*
		ch := make(chan int, 0)
		end := make(chan int, 0)
		go func(ch chan int) {
			//		time.Sleep(1000000000 * 100)
			ch <- 1
			//		time.Sleep(1000000000 * 10)
			ch <- 2
		}(ch)
		var ii int
		var jj int
		//L:
		for {
			select {
			case <-ch:
				ii++
				fmt.Println("iiiiii", ii)
				if ii >= 2 {
					//				break L
				}
			case <-end:
				jj = 100
				fmt.Println("jjjjjj", jj)
			}
		}
		var ti uint32
		for {
			ti = ti + 1
			time.Sleep(1000000000)
			//		fmt.Println("===", i)
			//		fmt.Println("end")
		}
	*/
	//////////////////////////////////////////////////////////////////

	fmt.Println("!!!!!!server done!")
}