|
 |
asp_components thread: components in vb vs session variables
Message #1 by Dragos Tudose <dtudose@y...> on Mon, 14 Jan 2002 12:45:45 -0800 (PST)
|
|
ok
as i was reading the wonderfull book
professional asp 3.0, (chapter 15, page 615 bottom and
page 618 top to middle-
where it says that components in vb should not be
stored in session variables)
, which i already love,
i thought how i could build a small chat aplication
with asp and vb.
in a few words said my problems are:
- i think that each user should be reprezented by an
instance of
a compoment written in vb. the problem is that i read
that these
objects should not be stored as session variables.so
how could i
put a mesage ( say this is a proprety of the component
with read only
asignement) from one object to another without finding
them anymore in the
memory...without beeing global as a sesion variable
is?
- say i could find a solution to the above issue..but
how about actually transmiting
the message from the server to the client's machine.
say i got the ip of that machine
, but after that..how do i do it with asp...or
vb...beats me...
thank u
__________________________________________________
Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!
http://promo.yahoo.com/videomail/
Message #2 by "Lewis, James" <James.Lewis@i...> on Mon, 14 Jan 2002 14:09:31 -0700
|
|
I have a small chat application that sounds similar to what you wanted to
do. I wrote a free-threaded dictionary that is stored in the application
object. Each entry in the dictionary hold an instance of a free-threaded
message queue component that I also wrote. The site works as such:
- At startup each each session adds itself to the dictionary, naming the key
after the session ID:
function Session_OnStart()
{
Application("chatdictionary").Add(Session.SessionID, new
ActiveXControl("ipni.messagequeue"));
}
- Each client then runs a remote script that reads every queue except its
own, and sends the received chat messages back to the browser as an XML
string:
function ReadMessages()
{
var szChatMessages = "<document>";
for(i=1;i<=Application("chatdictionary").count;i++)
{
szChatMessages = szChatMessages + "<message>";
szChatMessages = szChatMessages +
Application("chatdictionary").item(i).Read();
szChatMessages = szChatMessages + "</message>";
}
szChatMessages = szChatMessages + "</document>";
return szChatMessages;
}
- Each client also runs a remote script that writes to his own queue when
the user presses send:
function SendMessage(szMessage)
{
var objMyQ = Application("chatdictionary").Item(Session.SessionID);
objMyQ.Write(szMessage);
}
In this way, a simple chat room is created.
It is extremely important for all objects to be free-threaded because access
to the dictionary and the queue can be concurrent and therefore must be
thread-safe.
You can learn more about remote scripting at
http://msdn.microsoft.com/scripting. If you need some pointers on creating
those dictionaries or queues I can help, but hands down, I can only help if
you know C++ : )
J
-----Original Message-----
From: Dragos Tudose [mailto:dtudose@y...]
Sent: Monday, January 14, 2002 1:46 PM
To: ASP components
Subject: [asp_components] components in vb vs session variables
ok
as i was reading the wonderfull book
professional asp 3.0, (chapter 15, page 615 bottom and
page 618 top to middle-
where it says that components in vb should not be
stored in session variables)
, which i already love,
i thought how i could build a small chat aplication
with asp and vb.
in a few words said my problems are:
- i think that each user should be reprezented by an
instance of
a compoment written in vb. the problem is that i read
that these
objects should not be stored as session variables.so
how could i
put a mesage ( say this is a proprety of the component
with read only
asignement) from one object to another without finding
them anymore in the
memory...without beeing global as a sesion variable
is?
- say i could find a solution to the above issue..but
how about actually transmiting
the message from the server to the client's machine.
say i got the ip of that machine
, but after that..how do i do it with asp...or
vb...beats me...
thank u
__________________________________________________
Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!
http://promo.yahoo.com/videomail/
$subst('Email.Unsub')
$subst('Email.Unsub').
Message #3 by Dragos Tudose <dtudose@y...> on Mon, 14 Jan 2002 13:16:32 -0800 (PST)
|
|
thank u..i'll have to sit and chew the code for a
while as i'm a beginner in vb.
__________________________________________________
Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!
http://promo.yahoo.com/videomail/
Message #4 by dtudose@y... on Thu, 17 Jan 2002 21:25:19
|
|
ok
first thing to say..
i noticed your components are in C not in VB..which
explains how u made them free threaded
then ..
i'm thinking about the msmq service.
in the chat project i'm studying the posibility
of each user beeing served as a msmq component put
in the dictionary..put in the application object as u told me.
messages are ariving from the users to each queue he or she owns.
in paralel a service or an exe on the server must process the
incoming synchronously or asynchronously.
one problem is that in asp..as i read form pro asp u can't do it async.
that leaves me only the sync mode to deal with.
ok...but suppose we have this moment in time:
a user says: "how are u?"
another answers: "fine"
how can i control that in the process of harvesting the messages
(sync..mode) and
putting all in a variable and sending this variable to each user's
screen..i don't mess up like this:
"fine"
"how are u?"
thank u again
Message #5 by "Lewis, James" <James.Lewis@i...> on Fri, 18 Jan 2002 17:41:59 -0700
|
|
I understand your question, but I just wanted to clarify that I'm not using
MSMQ myself, though I think it will do a fine job for what you're after if
it has automation interfaces.
Anyway, I think to keep the messages straight you will want two things:
1. Queue management - When you post a message (publisher), the publisher
should publish his message to all queues except his own. While he is
publishing, he really should lock ALL subscriber queues using some global
semaphore (see next point) to ensure that he isn't half done publishing
before someone else sees his message, and replies before the first message
has been completely disseminated.
2. Concurrency management - I satisfied my concurrency management through a
COM object I call a lock manager. I wrote this lock manager because the only
really good concurrency object in IIS is the Application.Lock method. The
bad thing about Application.Lock is that it's global; even simulation of
multiple locks with arrays and counters ultimately boils down to that single
lock, which doesn't scale very well. Anyway, back to the point - if you
design this thing such that all subscribers agree to acquire the lock before
they publish, you guarantee that the messages will come out in order. So if
one guy says "hi", his remote script goes to the server, locks all the
queues (using whatever lock you decide to use), publishes "Hi" to all
participants, then releases the lock. While you are publishing right up to
the very last nanosecond before you release the lock, subscribers may be
pulling the message you just sent off of their queues. Further more, suppose
that you are about half way done publishing when the first recipient already
writes back "hi back". In order to send the "hi back" message, his publish
routine by design must attempt to acquire the lock, and in doing so, will
block until the first message "hi" has been published to all queues, and
then acquire the lock as soon as the "hi" publisher releases it. This is a
very classic multi-threading paradigm which should suite your needs quite
well.
Lastly, to get this thing up and running, you can certainly prototype using
the Application.Lock method - just keep in mind the design could be enhanced
in the future. So all things said, your remote scripts would look something
like:
function Publish(szMessage)
{
Application.Lock();
for all subscribers except me
{
subscriber->publish(szMessage);
}
Application.Unlock();
}
function Read()
{
while still messages in my Q
build XML string with messages
{
<document>
<message>
hi there
yo anyone here
yes
</message>
<message>
go away
</message>
</document>
}
}
Note that because the publish method does the locking, and the queue MUST be
free threaded, it's safe to read the queue even while it's being written to,
and therefore you don't need a lock to read.
Hope this helps!!
J
-----Original Message-----
From: dtudose@y... [mailto:dtudose@y...]
Sent: Thursday, January 17, 2002 2:25 PM
To: ASP components
Subject: [asp_components] RE: components in vb vs session variables
ok
first thing to say..
i noticed your components are in C not in VB..which
explains how u made them free threaded
then ..
i'm thinking about the msmq service.
in the chat project i'm studying the posibility
of each user beeing served as a msmq component put
in the dictionary..put in the application object as u told me.
messages are ariving from the users to each queue he or she owns.
in paralel a service or an exe on the server must process the
incoming synchronously or asynchronously.
one problem is that in asp..as i read form pro asp u can't do it async.
that leaves me only the sync mode to deal with.
ok...but suppose we have this moment in time:
a user says: "how are u?"
another answers: "fine"
how can i control that in the process of harvesting the messages
(sync..mode) and
putting all in a variable and sending this variable to each user's
screen..i don't mess up like this:
"fine"
"how are u?"
thank u again
$subst('Email.Unsub')
$subst('Email.Unsub').
Message #6 by Dragos Tudose <dtudose@y...> on Sat, 19 Jan 2002 12:09:18 -0800 (PST)
|
|
thanks J.i'll study in every detail what u send me
here.
__________________________________________________
Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!
http://promo.yahoo.com/videomail/
|
|
 |