Example #1
0
func main() {
	version()
	fmt.Printf("built on %s\n", BuildTime())
	flag.Parse()
	cfg := NewRouterConfig(*InputConfFile)
	err := cfg.LoadConfig()
	if err != nil {
		glog.Error(err.Error())
		return
	}
	p := link.PacketN(2, link.BigEndianBO, link.LittleEndianBF)

	server, err := link.Listen(cfg.TransportProtocols, cfg.Listen, p)
	if err != nil {
		glog.Error(err.Error())
		return
	}
	glog.Info("server start: ", server.Listener().Addr().String())

	r := NewRouter(cfg)
	go r.subscribeChannels()
	server.AcceptLoop(func(session *link.Session) {

	})
}
Example #2
0
func main() {
	version()
	fmt.Printf("built on %s\n", BuildTime())
	flag.Parse()
	cfg := NewMsgServerConfig(*InputConfFile)
	err := cfg.LoadConfig()
	if err != nil {
		glog.Error(err.Error())
		return
	}

	ms := NewMsgServer(cfg)

	p := link.PacketN(2, link.BigEndianBO, link.LittleEndianBF)

	ms.server, err = link.Listen(cfg.TransportProtocols, cfg.Listen, p)
	if err != nil {
		panic(err)
	}
	glog.Info("server start:", ms.server.Listener().Addr().String())

	ms.createChannels()
	go ms.scanDeadSession()

	ms.server.AcceptLoop(func(session *link.Session) {
		glog.Info("client ", session.Conn().RemoteAddr().String(), " | in")

		go handleSession(ms, session)
	})
}
Example #3
0
func main() {
	version()
	fmt.Printf("built on %s\n", BuildTime())
	flag.Parse()
	cfg := NewGatewayConfig(*InputConfFile)
	err := cfg.LoadConfig()
	if err != nil {
		glog.Error(err.Error())
		return
	}

	p := link.PacketN(2, link.BigEndianBO, link.LittleEndianBF)

	server, err := link.Listen(cfg.TransportProtocols, cfg.Listen, p)
	if err != nil {
		glog.Error(err.Error())
		return
	}
	glog.Info("server start: ", server.Listener().Addr().String())

	server.AcceptLoop(func(session *link.Session) {
		glog.Info("client ", session.Conn().RemoteAddr().String(), " | in")
		msgServer := common.SelectServer(cfg.MsgServerList, cfg.MsgServerNum)

		err = session.Send(link.Binary(msgServer))
		if err != nil {
			glog.Error(err.Error())
			return
		}
		session.Close(nil)
		glog.Info("client ", session.Conn().RemoteAddr().String(), " | close")
	})
}
Example #4
0
func (self *Manager) connectMsgServer(ms string) (*link.Session, error) {
	p := link.PacketN(2, link.BigEndianBO, link.LittleEndianBF)
	client, err := link.Dial("tcp", ms, p)
	if err != nil {
		glog.Error(err.Error())
		panic(err)
	}

	return client, err
}
Example #5
0
func main() {
	flag.Parse()
	cfg, err := LoadConfig(*InputConfFile)
	if err != nil {
		glog.Error(err.Error())
		return
	}

	p := link.PacketN(2, link.BigEndianBO, link.LittleEndianBF)

	gatewayClient, err := link.Dial("tcp", cfg.GatewayServer, p)
	if err != nil {
		panic(err)
	}

	fmt.Println("input id :")
	var input string
	if _, err := fmt.Scanf("%s\n", &input); err != nil {
		glog.Error(err.Error())
	}

	inMsg, err := gatewayClient.Read()
	if err != nil {
		glog.Error(err.Error())
	}
	glog.Info(string(inMsg.Get()))

	gatewayClient.Close(nil)

	msgServerClient, err := link.Dial("tcp", string(inMsg.Get()), p)
	if err != nil {
		panic(err)
	}

	glog.Info("test.. send id...")
	cmd := protocol.NewCmdSimple()

	cmd.CmdName = protocol.SEND_CLIENT_ID_CMD
	cmd.Args = append(cmd.Args, input)

	err = msgServerClient.Send(link.JSON{
		cmd,
	})
	if err != nil {
		glog.Error(err.Error())
	}

	go heartBeat(cfg, msgServerClient)

	glog.Info("test.. send create topic...")

	cmd = protocol.NewCmdSimple()

	cmd.CmdName = protocol.CREATE_TOPIC_CMD

	fmt.Println("input topic name :")
	if _, err = fmt.Scanf("%s\n", &input); err != nil {
		glog.Error(err.Error())
	}

	cmd.Args = append(cmd.Args, input)

	err = msgServerClient.Send(link.JSON{
		cmd,
	})
	if err != nil {
		glog.Error(err.Error())
	}

	glog.Info("test.. send join topic...")

	cmd = protocol.NewCmdSimple()

	cmd.CmdName = protocol.JOIN_TOPIC_CMD

	fmt.Println("input topic name :")
	if _, err = fmt.Scanf("%s\n", &input); err != nil {
		glog.Error(err.Error())
	}

	cmd.Args = append(cmd.Args, input)

	err = msgServerClient.Send(link.JSON{
		cmd,
	})
	if err != nil {
		glog.Error(err.Error())
	}

	glog.Info("test.. send send topic msg...")

	cmd = protocol.NewCmdSimple()

	cmd.CmdName = protocol.SEND_MESSAGE_TOPIC_CMD

	fmt.Println("input topic name :")
	if _, err = fmt.Scanf("%s\n", &input); err != nil {
		glog.Error(err.Error())
	}

	cmd.Args = append(cmd.Args, input)

	fmt.Println("input topic msg :")
	if _, err = fmt.Scanf("%s\n", &input); err != nil {
		glog.Error(err.Error())
	}

	cmd.Args = append(cmd.Args, input)

	err = msgServerClient.Send(link.JSON{
		cmd,
	})
	if err != nil {
		glog.Error(err.Error())
	}

	defer msgServerClient.Close(nil)

	msgServerClient.ReadLoop(func(msg link.InBuffer) {
		glog.Info(string(msg.Get()))
	})

	glog.Flush()
}