Exemplo n.º 1
0
func (this *Proxy) Run() {
	ProxyLog.Info(">>begin to load proxyconfig.ini...")
	err := ProxyConf.Init()
	if err != nil {
		ProxyLog.Error(">>load proxyconfig.ini error:(", err)
		return
	}
	ProxyLog.Info(">>proxyconfig.ini load successful :)")
	//开始启动节点服务
	ProxyLog.Info(">>begin to load NodeService...")
	//判断节点服务是否启动成功
	err = this.n.InitService()
	if err != nil {
		ProxyLog.Error(">>load NodeService error,", err)
		return
	}

	//开始启动代理服务
	ProxyLog.Info(">>begin to load ProxyService...")
	err = this.p.InitService()
	//判断代理服务是否启动成功
	if err != nil {
		ProxyLog.Info(">>load ProxyService error,", err)
		return
	}
	//等待业务处理或者正常退出
	ProxyLog.Info(">>Proxy is running:)")
	console.CheckInput()
	this.ShutDown()

}
Exemplo n.º 2
0
func main() {
	fmt.Println("time = ", time.Now().Second())
	runtime.GOMAXPROCS(runtime.NumCPU() - 1)
	s1 := NewMyServer()
	err := s1.Init(`{"ip":"127.0.0.1","port":12000}`)
	if err != nil {
		fmt.Println("net server init err,", err)
		return
	}

	s1.SetListenAddress("0.0.0.0")
	s1.SetListenPort(12000)

	s1.SetPackParser(netio.NewDefaultParser())

	s1.SetPackDispatcher(NewServerDispatcher())

	s1.GetPackDispatcher().AddPackEventListener("myserver", s1)
	s1.SetQos(netqos.NewServerQos())
	s1.GetQos().SetEnable(true)
	s1.GetQos().Stat()

	go s1.Start() //启动服务器

	console.CheckInput()
	s1.Close()
}
Exemplo n.º 3
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU() - 1)

	//创建N个客户端
	clientList := make(map[int]*MyClient)
	for i := 0; i < 3000; i++ {
		go func() {
			c1 := NewMyClient()
			c1.SetPackDispatcher(netio.NewDefaultPackDispatcher())
			c1.SetPackParser(netio.NewDefaultParser())
			c1.SetServerAddress("192.168.15.26")
			c1.SetServerPort(12000)
			c1.GetPackDispatcher().AddPackEventListener(strconv.Itoa(i+1), c1)
			err := c1.Connect() //启动客户端,看乒乓能不能打起来,哈哈!
			if err != nil {
				fmt.Println("client error,", err)
			}
			clientList[i+1] = c1

			login := protocol_login.Login_Req{}
			login.Packet = packet.NewEmptyPacket()
			login.CmdID = 0x01
			login.UserName = "******"
			login.PWD = "1q2323"
			buf := login.EncodePacket(512)
			time.Sleep(20 * time.Millisecond)
			//fmt.Println("client send data :", buf.GetData())
			for {
				time.Sleep(time.Millisecond * 500)
				c1.Write(buf.GetData())
			}

		}()

	}

	console.CheckInput()

}