How controller concurrently sessions with Json Assembly

Aug 12, 2011 at 4:05 AM
Edited Aug 12, 2011 at 4:06 AM

Hi kerryjiang, i have a new cuestion, how i control concurrently sessions with Json Assembly, when exectute 2 sends, for each one i send a different object json in to the one call function javascript.

My code is

public class CHAT : JsonSubCommand
    {
        private static object m_SessionSyncRoot = new object();
       // private object m_SessionSyncRoot = new object();

        protected override void ExecuteJsonCommand(WebSocketSession session, ChatMessage commandInfo)
        {

            //Save to database or despacth to other session?

            string message = this.SerializeObject(commandInfo);
            this.SendToAll(message, session.AppServer.GetAllSessions());
        }


        void SendToAll(string message, IEnumerable m_sessions)
        {
            lock (m_SessionSyncRoot)
            {
                foreach (var s in m_sessions)
                {
                    //s.SendResponse(message);
                    s.SendResponseAsync(message);
                }
            }
        }
}
Help please,
Thanks in advance
Coordinator
Aug 12, 2011 at 4:09 AM

Yes, you can do like that!