Example #1
0
func (server *Server) Cmd(data []byte) {
	var cmd Cmd
	err := json.Unmarshal(data, &cmd)
	if err != nil {
		loger.Println("cmd json unmarshal error:", err.Error())
	}

	//dispatch cmd
	switch cmd.Code {
	case CMD_PING:
		stat, _ := json.Marshal(utils.SysStat())
		ret := &Cmd{CMD_PING, stat}
		buf, _ := json.Marshal(ret)

		_, err := server.Send(buf)
		if err != nil {
			loger.Println("send error,", err.Error())
		}
		break
	}
}
Example #2
0
func NewServer() *Server {
	return &Server{
		stat: utils.SysStat(),
	}
}