本文整理匯總了Golang中github.com/oikomi/FishChatServer/protocol.CmdSimple類的典型用法代碼示例。如果您正苦於以下問題:Golang CmdSimple類的具體用法?Golang CmdSimple怎麽用?Golang CmdSimple使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了CmdSimple類的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: parseProtocol
func (self *MsgServer) parseProtocol(cmd []byte, session *libnet.Session) error {
var c protocol.CmdSimple
err := json.Unmarshal(cmd, &c)
if err != nil {
glog.Error("error:", err)
return err
}
pp := NewProtoProc(self)
switch c.GetCmdName() {
case protocol.SEND_PING_CMD:
err = pp.procPing(&c, session)
if err != nil {
glog.Error("error:", err)
return err
}
case protocol.SUBSCRIBE_CHANNEL_CMD:
pp.procSubscribeChannel(&c, session)
case protocol.SEND_CLIENT_ID_CMD:
err = pp.procClientID(&c, session)
if err != nil {
glog.Error("error:", err)
return err
}
case protocol.SEND_MESSAGE_P2P_CMD:
err = pp.procSendMessageP2P(&c, session)
if err != nil {
glog.Error("error:", err)
return err
}
case protocol.ROUTE_MESSAGE_P2P_CMD:
err = pp.procRouteMessageP2P(&c, session)
if err != nil {
glog.Error("error:", err)
return err
}
case protocol.CREATE_TOPIC_CMD:
err = pp.procCreateTopic(&c, session)
if err != nil {
glog.Error("error:", err)
return err
}
case protocol.JOIN_TOPIC_CMD:
err = pp.procJoinTopic(&c, session)
if err != nil {
glog.Error("error:", err)
return err
}
case protocol.SEND_MESSAGE_TOPIC_CMD:
err = pp.procSendMessageTopic(&c, session)
if err != nil {
glog.Error("error:", err)
return err
}
}
return err
}
示例2: cmd_sendto_rsp
func cmd_sendto_rsp(self *Client, c *protocol.CmdSimple) error {
fmt.Println(c.GetCmdName() + " returns: " + c.GetArgs()[0])
if c.GetArgs()[0] == protocol.RSP_SUCCESS {
fmt.Println("uuid: " + c.GetArgs()[1])
}
return nil
}
示例3: cmd_kick_rsp
func cmd_kick_rsp(self *Client, c *protocol.CmdSimple) error {
fmt.Println(c.GetCmdName() + " returns: " + c.GetArgs()[0])
if c.GetArgs()[0] != protocol.RSP_SUCCESS {
return errors.New(c.GetArgs()[0])
}
return nil
}
示例4: incoming_p2p_msg
// [msg, fromID, uuid]
func incoming_p2p_msg(self *Client, c *protocol.CmdSimple) error {
fmt.Println(c.GetArgs()[1] + " says : " + c.GetArgs()[0])
if len(c.GetArgs()) >= 3 {
cmd := protocol.NewCmdSimple(protocol.IND_ACK_P2P_STATUS_CMD)
cmd.AddArg(c.GetArgs()[2])
cmd.AddArg(protocol.P2P_ACK_READ)
cmd.AddArg(c.GetArgs()[1])
err := self.session.Send(libnet.Json(cmd))
if err != nil {
log.Error(err.Error())
}
}
return nil
}
示例5: incoming_topic_msg
func incoming_topic_msg(self *Client, c *protocol.CmdSimple) error {
msg := c.GetArgs()[0]
topicName := c.GetArgs()[1]
fromID := c.GetArgs()[2]
fromType := c.GetArgs()[3]
fmt.Println("Topic message received :")
fmt.Println(" TopicName :" + topicName)
fmt.Println(" FromID :" + fromID)
fmt.Println(" FromType :" + fromType)
fmt.Println(" Message :" + msg)
return nil
}
示例6: parseProtocol
func (self *Gateway) parseProtocol(cmd []byte, session *libnet.Session) error {
var c protocol.CmdSimple
err := json.Unmarshal(cmd, &c)
if err != nil {
return err
}
pp := NewProtoProc(self)
switch c.GetCmdName() {
case protocol.REQ_LOGIN_CMD:
err = pp.procLogin(&c, session)
if err != nil {
return err
}
}
return err
}
示例7: login_server
func login_server(self *Client) error {
var err error
self.session, err = libnet.Dial("tcp", self.msAddr)
if err != nil {
panic(err)
}
fmt.Println("req to login msg server...")
cmd := protocol.NewCmdSimple(protocol.REQ_LOGIN_CMD)
cmd.AddArg(self.clientID)
cmd.AddArg(self.uuid)
err = self.session.Send(libnet.Json(cmd))
if err != nil {
log.Error(err.Error())
return err
}
var c protocol.CmdSimple
err = self.session.ProcessOnce(func(msg *libnet.InBuffer) error {
log.Info(string(msg.Data))
err = json.Unmarshal(msg.Data, &c)
if err != nil {
log.Error("error:", err)
}
return nil
})
if err != nil {
log.Error(err.Error())
}
if c.GetArgs()[0] != protocol.RSP_SUCCESS {
log.Errorf("login msgserver error: %s", c.GetArgs()[0])
return errors.New(c.GetArgs()[0])
}
fmt.Println("login msg server SUCCESS")
return nil
}
示例8: main
func main() {
flag.Parse()
cfg, err := LoadConfig(*InputConfFile)
if err != nil {
glog.Error(err.Error())
return
}
fmt.Println("req GatewayServer...")
gatewayClient, err := libnet.Dial("tcp", cfg.GatewayServer)
if err != nil {
panic(err)
}
//glog.Info("...")
cmd := protocol.NewCmdSimple(protocol.REQ_MSG_SERVER_CMD)
err = gatewayClient.Send(libnet.Json(cmd))
if err != nil {
glog.Error(err.Error())
}
fmt.Println("input id :")
var input string
if _, err := fmt.Scanf("%s\n", &input); err != nil {
glog.Error(err.Error())
}
var c protocol.CmdSimple
err = gatewayClient.ProcessOnce(func(msg *libnet.InBuffer) error {
glog.Info(string(msg.Data))
err = json.Unmarshal(msg.Data, &c)
if err != nil {
glog.Error("error:", err)
}
return nil
})
if err != nil {
glog.Error(err.Error())
}
gatewayClient.Close()
fmt.Println("req GatewayServer end...")
msgServerClient, err := libnet.Dial("tcp", string(c.GetArgs()[0]))
if err != nil {
panic(err)
}
fmt.Println("send your id...")
cmd = protocol.NewCmdSimple(protocol.SEND_CLIENT_ID_CMD)
cmd.AddArg(input)
err = msgServerClient.Send(libnet.Json(cmd))
if err != nil {
glog.Error(err.Error())
}
go heartBeat(cfg, msgServerClient)
//glog.Info("the msg you want to send...")
go msgServerClient.Process(func(msg *libnet.InBuffer) error {
//glog.Info(string(msg.Data))
err = json.Unmarshal(msg.Data, &c)
if err != nil {
glog.Error("error:", err)
}
fmt.Println(c.GetArgs()[1] + " says : " + c.GetArgs()[0])
return nil
})
for {
cmd = protocol.NewCmdSimple(protocol.SEND_MESSAGE_P2P_CMD)
fmt.Println("send the id you want to talk :")
if _, err = fmt.Scanf("%s\n", &input); err != nil {
glog.Error(err.Error())
}
cmd.AddArg(input)
fmt.Println("input msg :")
if _, err = fmt.Scanf("%s\n", &input); err != nil {
glog.Error(err.Error())
}
cmd.AddArg(input)
fmt.Println("input my ID :")
if _, err = fmt.Scanf("%s\n", &input); err != nil {
glog.Error(err.Error())
}
cmd.AddArg(input)
err = msgServerClient.Send(libnet.Json(cmd))
if err != nil {
//.........這裏部分代碼省略.........
示例9: login_gateway
// return (ClientID, MsgServerAddr)
func login_gateway(self *Client) error {
fmt.Println("req GatewayServer...")
gatewayClient, err := libnet.Dial("tcp", self.cfg.GatewayServer)
if err != nil {
panic(err)
}
cmd := protocol.NewCmdSimple(protocol.REQ_LOGIN_CMD)
cmd.AddArg(self.clientID)
cmd.AddArg(self.clientType)
cmd.AddArg(self.clientPwd)
err = gatewayClient.Send(libnet.Json(cmd))
if err != nil {
log.Error(err.Error())
}
var c protocol.CmdSimple
err = gatewayClient.ProcessOnce(func(msg *libnet.InBuffer) error {
log.Info(string(msg.Data))
err = json.Unmarshal(msg.Data, &c)
if err != nil {
log.Error("error:", err)
}
return nil
})
if err != nil {
log.Error(err.Error())
}
gatewayClient.Close()
fmt.Println("req GatewayServer end...")
if c.GetArgs()[0] != protocol.RSP_SUCCESS {
log.Errorf("login gateway error: %s", c.GetArgs()[0])
return errors.New(c.GetArgs()[0])
}
self.uuid = c.GetArgs()[1]
self.msAddr = c.GetArgs()[2]
return nil
}
示例10: cmd_login
func cmd_login(self *Client, args []string) error {
if self.bLogin {
fmt.Println("You are already login, pls logout first")
return nil
}
if len(args) != 3 && len(args) != 4 {
return common.SYNTAX_ERROR
}
if args[2] != "D" && args[2] != "d" && args[2] != "C" && args[2] != "c" {
return common.SYNTAX_ERROR
}
self.clientID = args[1]
if args[2] == "D" || args[2] == "d" {
self.clientType = protocol.DEV_TYPE_WATCH
} else if args[2] == "C" || args[2] == "c" {
self.clientType = protocol.DEV_TYPE_CLIENT
} else {
}
self.clientPwd = ""
if self.clientType == protocol.DEV_TYPE_CLIENT {
if len(args) != 4 {
return common.SYNTAX_ERROR
}
self.clientPwd = args[3]
}
// Load config
fmt.Println("config file:" + *InputConfFile)
fmt.Println("config file loaded")
err := login_gateway(self)
if err != nil {
panic(err)
}
err = login_server(self)
if err != nil {
panic(err)
}
self.bLogin = true
go heartBeat(self.cfg, self.session)
var c protocol.CmdSimple
go self.session.Process(func(msg *libnet.InBuffer) error {
fmt.Println(string(msg.Data))
err = json.Unmarshal(msg.Data, &c)
if err != nil {
log.Error("error:", err)
}
fmt.Println("msg received is : " + c.GetCmdName())
switch c.GetCmdName() {
case protocol.RSP_GET_TOPIC_LIST_CMD:
cmd_topic_rsp(self, &c)
case protocol.RSP_GET_TOPIC_PROFILE_CMD:
cmd_topic_profile_rsp(self, &c)
case protocol.RSP_CREATE_TOPIC_CMD:
cmd_new_rsp(self, &c)
case protocol.RSP_JOIN_TOPIC_CMD:
cmd_join_rsp(self, &c)
case protocol.RSP_QUIT_TOPIC_CMD:
cmd_quit_rsp(self, &c)
case protocol.RSP_ADD_2_TOPIC_CMD:
cmd_add_rsp(self, &c)
case protocol.RSP_KICK_TOPIC_CMD:
cmd_kick_rsp(self, &c)
case protocol.RSP_SEND_P2P_MSG_CMD:
cmd_sendto_rsp(self, &c)
case protocol.IND_ACK_P2P_STATUS_CMD:
fmt.Println("msg sent [uuid=" + c.GetArgs()[0] + "] status: " + c.GetArgs()[1])
case protocol.IND_SEND_P2P_MSG_CMD:
incoming_p2p_msg(self, &c)
case protocol.IND_SEND_TOPIC_MSG_CMD:
incoming_topic_msg(self, &c)
}
return nil
})
return nil
}
示例11: cmd_send_rsp
func cmd_send_rsp(self *Client, c *protocol.CmdSimple) error {
fmt.Println(c.GetCmdName() + " returns: " + c.GetArgs()[0])
return nil
}
示例12: cmd_topic_profile_rsp
func cmd_topic_profile_rsp(self *Client, c *protocol.CmdSimple) error {
var num int
fmt.Println(c.GetCmdName() + " returns: " + c.GetArgs()[0])
if c.GetArgs()[0] != protocol.RSP_SUCCESS {
return errors.New(c.GetArgs()[0])
}
fmt.Println("GET_TOPIC_PROFILE returns : ")
fmt.Println(" topicName: " + c.GetArgs()[1])
fmt.Println(" creator: " + c.GetArgs()[2])
fmt.Println(" members[]: ")
num = (len(c.GetArgs()) - 3) / 3
index := 0
for {
if index == num {
break
} else {
fmt.Println(" " + c.GetArgs()[3+3*index] + "\t, " + c.GetArgs()[3+3*index+1] + "\t, " + c.GetArgs()[3+3*index+2])
index++
}
}
return nil
}
示例13: cmd_topic_rsp
func cmd_topic_rsp(self *Client, c *protocol.CmdSimple) error {
var num int
var err error
fmt.Println(c.GetCmdName() + " returns: " + c.GetArgs()[0])
if c.GetArgs()[0] != protocol.RSP_SUCCESS {
return errors.New(c.GetArgs()[0])
}
if num, err = strconv.Atoi(c.GetArgs()[1]); err != nil {
fmt.Println(err.Error())
log.Error(err.Error())
return err
}
fmt.Println("GET_TOPIC_LIST returns (" + c.GetArgs()[1] + "): ")
index := 0
for {
if index == num {
break
} else {
fmt.Println(c.GetArgs()[2+index])
index++
}
}
return nil
}
示例14: main
func main() {
flag.Parse()
cfg, err := LoadConfig(*InputConfFile)
if err != nil {
glog.Error(err.Error())
return
}
gatewayClient, err := libnet.Dial("tcp", cfg.GatewayServer)
if err != nil {
panic(err)
}
glog.Info("req msg_server...")
cmd := protocol.NewCmdSimple(protocol.REQ_MSG_SERVER_CMD)
err = gatewayClient.Send(libnet.Json(cmd))
if err != nil {
glog.Error(err.Error())
}
fmt.Println("input id :")
var input string
if _, err := fmt.Scanf("%s\n", &input); err != nil {
glog.Error(err.Error())
}
var c protocol.CmdSimple
err = gatewayClient.ProcessOnce(func(msg *libnet.InBuffer) error {
glog.Info(string(msg.Data))
err = json.Unmarshal(msg.Data, &c)
if err != nil {
glog.Error("error:", err)
}
return nil
})
if err != nil {
glog.Error(err.Error())
}
gatewayClient.Close()
msgServerClient, err := libnet.Dial("tcp", string(c.GetArgs()[0]))
if err != nil {
panic(err)
}
msgServerMap[string(c.GetArgs()[0])] = msgServerClient
glog.Info("test.. send id...")
cmd = protocol.NewCmdSimple(protocol.SEND_CLIENT_ID_CMD)
cmd.AddArg(input)
err = msgServerClient.Send(libnet.Json(cmd))
if err != nil {
glog.Error(err.Error())
}
go heartBeat(cfg, msgServerClient)
glog.Info("test.. send topic msg...")
cmd = protocol.NewCmdSimple(protocol.CREATE_TOPIC_CMD)
fmt.Println("want to create a topic (y/n) :")
if _, err := fmt.Scanf("%s\n", &input); err != nil {
glog.Error(err.Error())
}
if input == "y" {
fmt.Println("CREATE_TOPIC_CMD | input topic name :")
if _, err := fmt.Scanf("%s\n", &input); err != nil {
glog.Error(err.Error())
}
cmd.AddArg(input)
err = msgServerClient.Send(libnet.Json(cmd))
if err != nil {
glog.Error(err.Error())
}
}
cmd = protocol.NewCmdSimple(protocol.JOIN_TOPIC_CMD)
fmt.Println("JOIN_TOPIC_CMD | input topic name :")
if _, err := fmt.Scanf("%s\n", &input); err != nil {
glog.Error(err.Error())
}
cmd.AddArg(input)
fmt.Println("JOIN_TOPIC_CMD | input your ID :")
if _, err := fmt.Scanf("%s\n", &input); err != nil {
glog.Error(err.Error())
}
cmd.AddArg(input)
err = msgServerClient.Send(libnet.Json(cmd))
if err != nil {
glog.Error(err.Error())
}
err = msgServerClient.ProcessOnce(func(msg *libnet.InBuffer) error {
//.........這裏部分代碼省略.........