JSonSubCommandAssembly DROP 8

Sep 29, 2011 at 12:19 PM


does something change in using commandAssembly in Drop 8? It seem that [BasicSubProtocol].Initialize is no longer called by Setup.

Thank you


Sep 29, 2011 at 12:29 PM

Oh, it might be a bug.

I am checking this issue. If it is true it is a bug, I'll release a new drop to fix it.

Sep 29, 2011 at 12:43 PM

Great Kerry,

if i can help you, it seems that you check subProtocol Option as TWebSocketSession, but this option is never used, neighter  by JsonCommandAssembly nor by CustomSession (that use service type configuration).

In Drop 7, even though you still checked subProtocol, that check was always false and than m_SubProtocol.Initialize(config); was called.


Sep 29, 2011 at 1:12 PM

Could you download the latest code in mainline on the page below and then help me verify the issue you reported.


Sep 29, 2011 at 1:51 PM

I did it bu nothing seems changed.

I think the problem is here:


        private bool SetupSubProtocols(IServerConfig config)
            string subProtocolValue = config.Options.GetValue("subProtocol");

            if (string.IsNullOrEmpty(subProtocolValue))
                return true;

            var subProtocolTypes = subProtocolValue.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries).ToArray();

            if (subProtocolTypes != null && subProtocolTypes.Length > 0 && m_SubProtocols == null)
                m_SubProtocols = new Dictionary<string, ISubProtocol<TWebSocketSession>>(subProtocolTypes.Length, StringComparer.OrdinalIgnoreCase);

            foreach (var t in subProtocolTypes)
                ISubProtocol<TWebSocketSession> subProtocol;

                if (!AssemblyUtil.TryCreateInstance<ISubProtocol<TWebSocketSession>>(t, out subProtocol))
                    return false;

                if (m_SubProtocols.ContainsKey(subProtocol.Name))
                    Logger.LogError(string.Format("This sub protocol '{0}' has been defined! You cannot define duplicated sub protocols!", subProtocol.Name));
                    return false;

                m_SubProtocols.Add(subProtocol.Name, subProtocol);

            foreach (var subProtocol in m_SubProtocols.Values)
                if (!subProtocol.Initialize(config))
                    Logger.LogError(string.Format("Failed to initialize the sub protocol '{0}'!", subProtocol.Name));
                    return false;

            return true;

I think that If you only set commandAssembly="SuperWebSocket.Samples.JsonCommandAssembly" in config, the RED code is alway TRUE and th Yellow code is never reached.



Sep 29, 2011 at 1:54 PM

Cool, I have done another fix. Try again please, only get the class WebSocketServer.

Sep 29, 2011 at 2:09 PM

Ok, now the Assembly in commandAssembly="SuperWebSocket.Samples.JsonCommandAssembly" is initiliazed, but when i try to execute th CHAT command the customized code in SuperWebSocket.Samples.JsonCommandAssembly is not fired. I think that in the code below the first I THEN is always false because the SubProtocol collection only contains the BASIC subprotocol. Do you Agree?


        private void ExecuteSubCommand(TWebSocketSession session, StringCommandInfo subCommandInfo)
            ISubCommand<TWebSocketSession> subCommand;

            if (session.SubProtocol.TryGetCommand(subCommandInfo.Key, out subCommand))
                session.CurrentCommand = subCommandInfo.Key;
                subCommand.ExecuteCommand(session, subCommandInfo);
                session.PrevCommand = subCommandInfo.Key;

                if (Config.LogCommand)
                    Logger.LogError(session, string.Format("Command - {0} - {1}", session.IdentityKey, subCommandInfo.Key));

            session.LastActiveTime = DateTime.Now;


Sep 29, 2011 at 2:52 PM

Sorry, could you check out this change?



Sep 29, 2011 at 3:05 PM

You got it!

Just i little thing more. In DROP 7 you set a warning about using subProtocol or standard flow. It was very helpfull.

                if (m_SubCommandsLoaded)
                    throw new Exception("You cannot set the NewMessageReceived handler if you have defined the commands of your sub protocol!");
Would be nice to warn (in whatever manner) again.

Kerry I want you to know that your work is really COOL!!!!.

Thank you very much


Sep 29, 2011 at 3:11 PM

Thanks, I'll think about your requirement!

I am very glad for you love SuperWebSocket.