Esempio n. 1
0
// message fetcher
func fetcher_task() {
	//connect to game service
	clients, err := services.GetAllService(services.SERVICE_GAME)
	if err != nil {
		log.Critical(err)
		os.Exit(-1)
	}
	for _, cli := range clients {
		service, _ := cli.(proto.GameServiceClient)
		stream, err := service.Notify(context.Background(), &proto.Game_Nil{})
		if err != nil {
			log.Critical(err)
			os.Exit(-1)
		}
		go func() {
			for {
				p, err := stream.Recv()
				if err == io.EOF {
					log.Infof("stream recv EOF err :%v", err)
					return
				}
				if err != nil {
					log.Critical("stream recv gs err", err)
					continue
				}
				registry.Deliver(p.Uid, p.Content)
			}
		}()
	}
}
Esempio n. 2
0
func init() {
	_default_forward = forwarder{}
	//TODO connect all game server and forward packet
	clients, err := services.GetAllService(services.SERVICE_GAME)
	if err != nil {
		log.Critical(err)
		os.Exit(-1)
	}
	for k, cli := range clients {
		service, _ := cli.(GameServiceClient)
		stream, err := service.Packet(context.Background())
		if err != nil {
			log.Critical(err)
			os.Exit(-1)
		}
		_default_forward.gs[k] = stream

	}
	for k, c := range _default_forward.gs {
		go _default_forward.recv(k, c)
	}
}