Non String Command Name

Jul 26, 2011 at 11:25 PM

I have a protocol which uses a single binary byte cast as an enumerator to specify the type of each command. Currently I have to convert this to a string and specify all my command name strings in order for the parser to match incoming commands.

Is there a way to change the type of the dictionary from strings to byte / enum? Would make the dictionary lookup more efficient, or could even use a switch statement.

Jul 27, 2011 at 2:29 AM

Yes, there is a way.



public class ECHO : CommandBase<EchoSession, MyCommandInfo>
        public override string Name
            get { return "0A"; }

        #region CommandBase<EchoSession> Members

        public override void ExecuteCommand(EchoSession session, MyCommandInfo commandInfo)



You can override the Name property by a HEX string like the code above.

There is a sample project named "GPSSocketServer" in QuickStart working like this. You should take a look at it.