Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Ajax
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #11 (permalink)  
Old September 21st, 2007, 06:10 AM
Authorized User
 
Join Date: Sep 2007
Location: , , .
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 :(

Reply With Quote
  #12 (permalink)  
Old September 21st, 2007, 06:23 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
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)
Reply With Quote
  #13 (permalink)  
Old September 21st, 2007, 09:00 AM
Authorized User
 
Join Date: Sep 2007
Location: , , .
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,

Reply With Quote
  #14 (permalink)  
Old September 21st, 2007, 09:17 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
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)
Reply With Quote
  #15 (permalink)  
Old September 21st, 2007, 09:44 AM
Authorized User
 
Join Date: Sep 2007
Location: , , .
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!

:)
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 08: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 06:53 AM
asp sending unknow problem powerMan Classic ASP Professional 0 October 4th, 2005 09:25 PM



All times are GMT -4. The time now is 10:52 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.