Bill W-My apologies

Results 1 to 2 of 2

Thread: Bill W-My apologies

  1. #1
    Join Date
    Dec 1969

    Default Bill W-My apologies

    You&#039re right. It wasn&#039t fair without the source code. <BR><BR>As for the virtual dir I think yes but the problem is the code. Here is the chat page and the entry page in folder chat_1 under the folder test.<BR><BR>Entry Page:<BR>Option Explicit<BR>response.Buffer = true<BR><BR>If trim(Request.Form("name")) = "" Then<BR><BR><BR><BR>&#060;form action="chat1.asp" method="POST"&#062;<BR> &#060;p align="center"&#062;&#060;font face="Arial"&#062;&#060;b&#062;Your name? &#060;/b&#062;&#060;/font&#062;<BR><BR> &#060;input type="text" size="20" name="Name"&#062;&#060;/p&#062;<BR> &#060;p align="center"&#062;&#060;input type="submit" name="Submit"<BR> value="Enter the chat "&#062;&#060;/p&#062;<BR>&#060;/form&#062;<BR><BR><BR>Else<BR> Dim users, refresh<BR> Session("name") = Request.Form("name")<BR><BR> If Application("NumUsers") = 0 Then<BR> ReDim temp1(50)<BR> ReDim temp2(50)<BR> Application("users") = temp1<BR> Application("refresh") = temp2<BR> End If<BR><BR> users = Application("users")<BR> refresh = Application("refresh")<BR><BR><BR> Dim i<BR> For i = 1 To 50<BR> If users(i) = "" Then<BR> users(i) = Session("name")<BR> refresh(i) = time<BR> Application.Lock<BR> Application("NumUsers") = Application("NumUsers") + 1<BR> Application.Unlock<BR> Exit For<BR> End If<BR> Next<BR> If i = 51 Then Response.Redirect "toomany.asp"<BR><BR> Application.Lock<BR> Application("users") = users<BR> Application("refresh") = refresh<BR> Application.Unlock<BR><BR> If not IsEmpty(Application("conversation")) Then <BR> Application.Lock<BR> Application("conversation") = "&#060;font face=arial color=#800000 size=2&#062;&#060;b&#062;&#060;i&#062;" & Session("name") & _<BR> " has come in.&#060;/b&#062;&#060;/i&#062;&#060;/font&#062;<BR>" & Application("conversation")<BR> Application.Unlock<BR> End If<BR><BR> Response.Redirect "room1.asp"<BR>End If<BR><BR><BR><BR><BR><BR>Chat Frame:<BR>Dim convo<BR>convo = Application("conversation")<BR>If Len(convo) &#062; 2000 Then<BR> convo = Left(convo, 2000)<BR> Application.Lock<BR> Application("conversation") = convo<BR> Application.Unlock<BR>End If<BR>Response.Write convo<BR><BR><BR>These same pages exist in a folder named chat_1 under the folder test_1.<BR><BR>I guess the easiest way to explain this is the tree looks like this:<BR><BR>www<BR> test<BR> chat_1<BR> chat_2<BR> test_1<BR> chat_1<BR> chat_2<BR> and so on<BR><BR>Hope I explained that well.<BR><BR>I see why the 2 are getting mixed. I think?? The sessions are the same?<BR>I just don&#039t know how to resolve it. <BR>Thanks Bill for responding.<BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default Why? It was reasonable question...

    I see a couple of problem areas in the code, but it wouldn&#039t account for the mixing of messages.<BR><BR>I would say that the mixing is definitely becuase you have two chat directories inside the same Virtual Directory. Why don&#039t you just make the actual Chat directories into virtual directories, directly, instead of putting them under yet other virtual dirs?<BR><BR>Bugs in your code:<BR><BR>You *must* put the Application.Lock/Unlock pair around *the entire code* that reads/modifies/writes the Application variables!<BR><BR>Let&#039s just extract some lines from you code (I&#039ve added line numbers to them, after the $$$ remark):<BR><BR>&#060;%<BR>users = Application("users") &#039 $$$ 1<BR>...<BR>users(i) = Session("name") &#039 $$$ 2<BR>...<BR>Application.Lock &#039 $$$ 3<BR>Application("users") = users &#039 $$$ 4<BR>Application.Unlock &#039 $$$ 5<BR>%&#062;<BR><BR>Now try out this scenario:<BR><BR>-- User A comes in and reads the array at line 1<BR>-- the code runs to the point where he is put into the users() array in line 2, in empty slot 17, say<BR>-- User A gets suspended<BR><BR>-- User B comes in and reads the array at line 1<BR>-- the code runs to the point where he is put into the users() array in line 2, in empty slot 17, say<BR>-- User B gets suspended<BR><BR>-- User A locks the app, puts the new version of the array into the app value, unlocks (lines 3,4,5)<BR>-- User B locks the app, puts the new version of the array into the app value, unlocks (lines 3,4,5)<BR><BR>BUT USER B JUST OVERWROTE WHAT USER A DID!<BR><BR>And that&#039s because *you* allowed user B to get a copy of the *same* array that user A had!<BR><BR>See it?<BR><BR>You need to put an Application.Lock just after this line:<BR>&nbsp; &nbsp; Session("name") = Request.Form("name")<BR>and the Application.Unlock just before this line:<BR>&nbsp; &nbsp; Response.Redirect "room1.asp"<BR>AND NO OTHER PLACES.<BR><BR>Well, except you need to do this:<BR>&nbsp; &nbsp; If i = 51 Then<BR>&nbsp; &nbsp; &nbsp; &nbsp; Application.Unlock <BR>&nbsp; &nbsp; &nbsp; &nbsp; Response.Redirect "toomany.asp"<BR>&nbsp; &nbsp; End If<BR>(because you don&#039t want to leave the page without unlocking).<BR><BR>Hokay?<BR><BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts