Command Help

Apr 24, 2014 at 6:10 PM
Edited Apr 24, 2014 at 7:06 PM
I am trying to figure out how can I build a sub command for the following scenario.

I will have . cs classes on my command such as:

and each of these classes with have methods such as:


most of these methods need to return Json objects.

Is there anyway I can make it so I can send commands to the server like :
UserMgr -register [json object]

Please help steering me in the right direction.
Apr 25, 2014 at 6:30 PM
I can do it like below but I am looking for a cleaner way so that I don't have to have repetitive code on every single command class.
    public class Command
        public string action { get; set; }
        public object data { get; set; }

    public class UserMgr : JsonSubCommand<Command>
        private string action;
        private object data;
        private WebSocketSession session;
        protected override void ExecuteJsonCommand(WebSocketSession session, Command cmd)
            this.session = session; 
            action = cmd.action;
            data =;
            MethodInfo method = this.GetType().GetMethod(action, BindingFlags.DeclaredOnly);
            method.Invoke(this, null);

        void Help()
            foreach (MethodInfo action in this.GetType().GetMethods(BindingFlags.DeclaredOnly))
                this.SendJsonMessage(session, action.Name);        


Client code

ws.send("UserMgr {'action':'Help'}");
Apr 26, 2014 at 1:31 PM
Completely wrong!

The command/subcommand of SuperWebSocket must be stateless.

What you should do is defining your subcommands to bridge your own business classes.
Apr 30, 2014 at 6:36 PM
Edited Apr 30, 2014 at 6:40 PM
My class is stateless., and bridging my own business logic is what it does the only thing it accomplishes is that it groups commands by category.

Its like having a subcommand for Math that contains actions Add , Multiply, and Divide