Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Ajax
|
Ajax the combination of XHTML, CSS, DOM, XML, XSLT, XMLHttpRequest, and JavaScript
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Ajax section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 21st, 2007, 05:10 AM
Authorized User
 
Join Date: Sep 2007
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Seems my problem is not resolved cause when I switch to another room, a wrong session is returned for user etc.
would you mind if I send you directly a part of my code to see where the mistake is?
I'm really in need of someone's help cause the clock is rushing and I'm behind my schedule :(

 
Old September 21st, 2007, 05:23 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Just post your server-side code here, try to simplify if possible. Can't guarantee anything, I too have a real job, two at the moment as I'm on secondment in Chicago as well as doing my normal London duties :)

--

Joe (Microsoft MVP - XML)
 
Old September 21st, 2007, 08:00 AM
Authorized User
 
Join Date: Sep 2007
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

you're really kind to do such a favor to me
here's my problem:
I have many rooms (channel) in which each user can log on and chat. when a few users are in the same room they can chat without any problem but when one of them switches to another room, the users in previous room cannot send/receive any text:
Code:
////server.aspx/////////////
protected void processLogin()
        {
            //Channel Data
            string channelname = Request.QueryString["c"].ToString();

            foreach (RoomInfo var in Global.RoomMgmt.RoomList)
            {
                if (!Global.Engine.ChannelExists(var.RoomID))
                {
                    //If channel doesn't exist, add a new one.
                    if (!Global.Engine.AddChannel(var.RoomID))
                    {
                        Response.Write(" ERROR: Maximal Channel Count Reached !");
                        return;
                    }
                } 
            }

            string user = Request.QueryString["u"].ToString();
            string ip = Request.QueryString["i"].ToString();
            string role = Request.QueryString["r"].ToString();

            Guid g = Guid.NewGuid();
            Global.Engine.GetChannel(Global.RoomMgmt.RoomList[0].RoomID).AddUser(g.ToString(), user, ip, role);

            //Save Session Data
            Session["userid"] = g.ToString();
            Session["username"] = user;
            Session["channel"] = Global.RoomMgmt.RoomList[0].RoomID;

            //Change Login Status
            Session["LoggedIn"] = "YES";

            Response.Redirect("ChatRoom.aspx?" + g.ToString() + "&u=" + user + "&r=" + role + "&c=" + 0);            
        } 
protected void processPostMsg()
        {
            string 
            user = (string)Session["username"];
            ...
            //Check Login Status
            if (!checkLoginStatus(user))
            {
                return;
            }

            string text = Request.QueryString[ "t" ];
            string to_uid = Request.QueryString["s"];
            string iswhisper = Request.QueryString [ "w" ];

            //Session Data

           string channelname = (string)Session["channel"];
            Thread.Sleep(Convert.ToInt32(Global.FloodControl)); 
            Global.Engine.GetChannel(channelname).AddText( user, to_uid, text, iswhisper );
        }

        protected void processGetMsg()
        {
            lock (syncRoot)
            {
                string userid = (string)Session["username"];
                if (!checkLoginStatus(userid))
                {
                    Response.Redirect("Login.aspx");
                    return;
                }

                string channelname = (string)Session["channel"];
                Response.Write(Global.Engine.GetChannel(channelname).GetPersonalBufferText(userid)); 
            }
        }

protected void processChangeTab()
        {//this function is called when user switches to another room
            if (Request.QueryString.Count == 0)
                return;

            //Channel Data
            string channelname = Request.QueryString["c"].ToString();

            if (!Global.Engine.ChannelExists(channelname))
            {
                //If channel doesn't exist, add a new one.
                if (!Global.Engine.AddChannel(channelname))
                {
                    Response.Write(" ERROR: Maximal Channel Count Reached !");
                    return;
                }
            }

            string user = Request.QueryString["u"].ToString();
            string ip = Request.QueryString["i"].ToString();
            string role = Request.QueryString["r"].ToString();
            Guid g = Guid.NewGuid();
            string prevChannelname = Request.QueryString["n"].ToString();

            if (prevChannelname != channelname)
            {
                Global.Engine.GetChannel(prevChannelname).Remove(user);
                Global.Engine.GetChannel(channelname).AddUser(g.ToString(), user, ip, role);

                //Save Session Data
                Session["userid"] = g.ToString();
                Session["username"] = user;
                Session["channel"] = channelname;

                //Change Login Status
                Session["LoggedIn"] = "YES";

                //Global.IsTabChanged = true;
            }
            Response.Redirect("ChatRoom.aspx?" + g.ToString() + "&u=" + user + "&r=" + role + "&c=" + Global.RoomMgmt.GetRoomIndex(channelname));             
        } protected bool checkLoginStatus(string userid)
        {
            //string userid = (string)Session["userid"];
            string channelname = (string)Session["channel"];

            if (channelname != null)
            {
                if (!Global.Engine.GetChannel(channelname).GuidExists(userid))
                {
                    Session["LoggedIn"] = "NO";
                    return false;
                }
                else
                {
                    return true;
                }
            }
            else
                return false;
        }
///////////////////////////////////
//////////ChatEngine.cs///////////
public void AddText(string guid, string to_uid, string text, string iswhisper)
        {
            object key = null ;

            foreach (DictionaryEntry e in users)
            {
                if (e.Value.ToString() == guid)
                {
                    key = e.Key;
                    break;
                }
            }
            if (text.Trim().Length == 0)
                return;

            if (text.Length > Convert.ToInt32(Global.TextCharLimit))
            {
                chat.Add(
                    new ChatMessage(
                        "UCHAT_SERVER",
                        "ALL",
                        this.MakeServerMessage(
                        string.Format(
                            textlimitfmt,
                            guid,//users[guid].ToString(),
                            text.Length,
                            Global.TextCharLimit
                        )
                        ),
                        "SERVER_MSG"
                    )
                );
                return;
            }

            while (chat.Count > maxbuffer)
            {
                chat.RemoveAt(0);
            }

            if (!pings.Contains(key.ToString()))
            {
                pings.Add(key.ToString());
            }

            string msgtype = "USER_MSG_NORMAL";
            if (iswhisper == "TRUE" )
            {
                msgtype = "USER_MSG_WHISPER";
            }

            chat.Add(
                new ChatMessage(
                    key.ToString(),
                    to_uid,
                    ParseText(users[key].ToString(), to_uid, text, msgtype),
                    msgtype
                )
            );
        }
public string GetPersonalBufferText( string guid )
        {            
            StringBuilder sb = new StringBuilder();
            lock (syncRoot)
            {
                object key = null;

                foreach (DictionaryEntry e in users)
                {
                    if (e.Value.ToString() == guid)
                    {
                        key = e.Key;
                        break;
                    }
                }
                try
                {
                    foreach (ChatMessage line in chat)
                    {
                        string msg = string.Empty;

                        switch (line.MessageType)
                        {
                            case "SERVER_MSG":
                            case "USER_MSG_NORMAL":
                                msg = line.Message;
                                break;
                            case "USER_MSG_WHISPER":
                                if (key.ToString() == line.ToUserID || key.ToString() == line.FromUserID)
                                {
                                    msg = line.Message;
                                }
                                break;
                            default:
                                msg = this.MakeServerMessage("Message Type Error!");
                                break;
                        }
                        sb.Append(msg);
                    }
                }
                catch (Exception)
                {
                }
            }
            return sb.ToString();
        }
Those are a part of my server side code, that are involved with the mentioned problem.
Thank you very much indeed,

 
Old September 21st, 2007, 08:17 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Sorry but trying to debug that sort of code without knowing what's happening behind the scenes and able to step into the code is nigh on impossible.
I'd like to help but that's more a paid assignment, not something one could reasonably expected to do via a forum :(

Good luck

--

Joe (Microsoft MVP - XML)
 
Old September 21st, 2007, 08:44 AM
Authorized User
 
Join Date: Sep 2007
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

okay I understand! I wanted to know if I had any obvious error
Thanks anyway Joe!

:)





Similar Threads
Thread Thread Starter Forum Replies Last Post
ResponseText property of XMLHTTPRequest Object prashantshekhar BOOK: Beginning Ajax with ASP.NET 1 August 28th, 2009 07:28 AM
Evaluate responseText from Server.aspx peace2007 Ajax 8 January 4th, 2008 06:47 AM
responseText not working in FireFox Coyote21 BOOK: Professional Ajax ISBN: 978-0-471-77778-6 0 July 13th, 2006 05:53 AM
asp sending unknow problem powerMan Classic ASP Professional 0 October 4th, 2005 08:25 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.