When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles
ASPFAQs.com
Message Board
Related Web Technologies
User Tips!
Coding Tips

Sections:
Sample Chapters
Commonly Asked Message Board Questions
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Security
Stump the SQL Guru!
XML Info
Information:
Feedback
Author an Article
ASP ASP.NET ASP FAQs Message Board Feedback
Print this page.
Published: Monday, April 10, 2000

ASP Instant Messaging, Part 2

By Ryan S.


  • Read Part 1

  • In Part 1 we discussed some of the basic theory behind messaging. In this part, we will look at the client code. First, let us define our initial functions for getting info outta the application variable, and then displaying it on the client.

    - continued -

    Sub CheckForMessages(fromUserID)
      'Now you see why I do not recommend this
      'for large scale operations!
      Application.Lock
    
      aChatDB.Filter = "FromID=" & fromUserID
      If not aChatDB.EOF Then
        Do While not aChatDB.EOF
         cChatDB.AddNew
         cChatDB("ToID") = aChatDB("ToID")
         cChatDB("toName") = aChatDB("ToName")
         cChatDB("FromID") = aChatDB("FromID")
         cChatDB("FromName") = aChatDB("FromName")
         cChatDB("TimeSent") = aChatDB("TimeSent")
         cChatDB("Message") = aChatDB("Message")
         cChatDB.Update
         aChatDB.Delete
         aChatDB.MoveNext
        Loop
      End If
      Application.UnLock
    End Sub
    

    Now, I do the .Delete on the aChatDB because the sender already has it in their cChatDB, so once the recipient has it in their cChatDB, it is redundant, so eliminating it from the server reduces the memory load of the application variable. (While I recognize at this point it now exists in two separate memory addresses in regards to the two cChatDBs, or potentially more if you opt for a variant of this, to be discussed later in the article, but, each of those optimally ends in 5 minutes, whereas the application variable is much trickier to clean up if left in this state.)

    Next, we need to have code to send messages.

    Sub SendMessage(ToID, toName, Message)
      cChatDB.AddNew
      cChatDB("ToID") = ToID
      cChatDB("toName") = ToName
      cChatDB("FromID") = Session("UserID")
      cChatDB("FromName") = Session("UserName")
      cChatDB("TimeSent") = Now
    
      'remove the Server.HTMLEncode to let users send HTML
      cChatDB("Message") = Server.HTMLEncode(Message)
      cChatDB.Update
    
      Application.Lock
      aChatDB.AddNew
      aChatDB("ToID") = ToID
      aChatDB("toName") = ToName
      aChatDB("FromID") = Session("UserID")
      aChatDB("FromName") = Session("UserName")
      aChatDB("TimeSent") = Now
      aChatDB("Message") = Server.HTMLEncode(Message)
      aChatDB.Update
      Application.Unlock
    
    End Sub
    

    If you notice, I have to lock and unlock the Application variable, because I have no clue if another user is perhaps filtering on it, thus corrupting the data. Clearly then, it is obvious why this fails in larger scales.

    In Part 3 we will look at how to display the ASP messages!

  • Read Part 3
  • Read Read Part 1


  • ASP.NET [1.x] [2.0] | ASPMessageboard.com | ASPFAQs.com | Advertise | Feedback | Author an Article