Example #1
0
func NewServer() (*Server, error) {
	// connect dao server
dao:
	daocli, err := rpc.Dial("tcp", cfg.DaoAddr())
	if err != nil {
		log.Warningf("dao server connect fail(err=%+v), try again...", err.Error())
		time.Sleep(1 * time.Second)
		goto dao
	}

	ctrl := make(chan string, 10)
game:
	cli, err := fw.NewClient(cfg.GameAddr(), &gameCliModel{}, ctrl)
	if err != nil {
		log.Error(err.Error())
		log.Warningf("game server connect fail(err=%+v), try again...", err.Error())
		time.Sleep(1 * time.Second)
		goto game
	}
	go cli.Loop()

	// daemon routine (to be done), with "ctrl"
	// ......
	////////////////////

	// new server
	serverInst = &Server{
		dao:       daocli,
		gameCli:   cli,
		gameCtrl:  ctrl,
		connIdAcc: 0,
		agents:    make(map[int]*fw.Agent, 1000),
	}
	return serverInst, nil
}
Example #2
0
func TestClient1(t *testing.T) {
	ctrl := make(chan string, 1)
	cli, err := fw.NewClient(cfg.AgentAddr(), &cowrobot.Clientmodel{}, ctrl)
	if err != nil {
		t.Error(err.Error())
		return
	}
	t.Log(cli)
	go cli.Loop()

	s := string(`{"cmd":104,"content":"{\"account\":\"testUtf\",\"psw\":\"pswlk22\"}"}`)
	cli.Send(s)
	time.Sleep(10 * time.Second)
	t.Log("end")
}