RE: Flash and pubsub...
"Adam Rifkin" <[email protected]>
| Newsgroups | gmane.comp.web.mod-pubsub.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi Jos,
We have added your FlashTunnel change to pubsub.py in CVS if you want to do
a cvs update. We called it kn_response_format=flash to avoid confusion with
the existing non-null-terminated kn_response_format=simple.
Thanks for the link to the base64 en/decoder for Flash (woo hoo, Creative Commons
Attribution-ShareAlike License!) and the JS <-> Flash articles.
Using Flash's "watch" function seems like a clever and serviceable solution to
"sending" the data from JS to Flash; using FSCommand or getURL to send from Flash
and JS also seems serviceable.
I have added the examples of the POST contents to the PubSub Protocol guide;
glad you found them useful. (Keep asking questions, they make the protocol
guide better... :)
Now for some responses...
> How are the kn_from paths constructed? In the example you gave, you created a
> tunnel using the following string (missing the POST/host etc data):
>
> "kn_response_format=flash;" +
> "do_method=route;" +
> "kn_from=/who/jos/s/24/kn_journal"
>
> Can the client define the kn_from paths? Or does the path get created by the server?
The client defines the kn_from path by inserting a randomly chosen session id into
a template like this, by convention:
/who/%userid%/s/%random%/kn_journal
where
%userid% is a machine-readable userid for the person running the application,
or "anonymous" if the application does not (or cannot) disclose this information
"s" is for session
%random% is a randomly chosen session identifier, which should be a globally-unique
identifier for any particular tunnel
> I've used this example and gotten it "working" (with several caveats), but i'm not
> really sure what the "/who/jos/s/24/kn_journal" means...
That's the topic that acts as a server-side proxy connecting to your application's tunnel.
> So, i've built a really basic tool...
>
> http://www.trapeze.com/r_and_d/pubsub/t2.fla
> and
> http://www.trapeze.com/r_and_d/pubsub/t2.swf
> (note - it's looking for the server on localhost on port 8008)
>
> ...for doing experimentation with the python pubsub.py server. It connects, and
> can send info. I've yet to get info back, other than a notification that I've
> established a route. I have sent a message to a /what/chat app running in a browser
> from it, which was pretty cool.
>
> I should also quickly say how the flash app works too! The bottom box is where you
> enter the info - just the
>
> "kn_response_type=simple;do_method=route;kn_from=/who/jos/s/24/kn_journal"
>
> type stuff - it automagically adds the POST headers to that. The upper box is
> where it echos what you are sending and any info you get back from the server...
This is a cool little app.
My web browser was able to reach port 8008 on localhost using port forwarding
but the "connect" button does not appear to connect properly. Error message
is "connect: Connection failed!" Any ideas?
> The only thing i've changed in the pubsup.py file is:
>
> in SimpleTunnel (ln ~481)
>
> <code>
> def encode(self, dict):
> """Same as ev_encode, except including the count and
> separators, so it can actually be sent on a tunnel."""
> # str = self.ev_encode(dict)
> str = self.ev_encode(dict) + chr(0)
> return "%d\n%s\n" % (len(str), str)
> </code>
>
> so i'm just tacking on an extra null byte (chr(0)) to the string to force flash
> to fire the onData handler. Not pretty, but it works for this...
Sounds reasonable to me. We have added this to pubsub.py in CVS if you want to do
a cvs update. We call it "FlashTunnel" and it supports kn_response_format=flash.
> So, to reiterate, i can do a do_method=route;kn_from=/who/jos/s/24/kn_journal
> and get a response from the server.
>
> I can do a do_method=notify;kn_to=/what/chat;kn_payload=hello and get it to show up
> in a browser running the chat1 app.
>
> Thats it so far, but good to get some progress! Again, the thing that i'm a bit unclear
> about now, is the paths used in kn_to and kn_from. I also have to dig into the python
> to figure out where it receives the POST data, so i can try to figure out why it drops
> the connection ...
This does sound like good progress. Congrats, and thanks for keeping us informed!
Also, feel free to have a look at the Python PubSub Client Library
mod_pubsub/python_pubsub/pubsublib.py
if you want to peruse fairly readable source code for what happens client-side for
connections, publish, and subscribe.
Adam
-----Original Message-----
From: hyakugei [mailto:[email protected]]
Sent: Wednesday, May 21, 2003 10:28 AM
To: Adam Rifkin
Cc: [email protected]; [email protected]
Subject: Re: [Mod-pubsub-developer] Flash and pubsub...
I wrote a base64 en/decoder for flash for another project, but its under an open license.
http://trapeze.com/r_and_d/as/base64.as
I found a couple of article on the whole JS <-> Flash communication thing here:
http://www.macromedia.com/support/flash/ts/documents/browser_support_matrix.htm
and
http://www.macromedia.com/support/flash/publishexport/scriptingwithflash/index.html
The biggest difficulty is "sending" the data from JS to Flash. I think the easiest way is to use the setProperty function from JS to set a specific property in Flash. Flash has a built in function called "watch", which will preform a callback when a "watched" property changes. So, in this way you could send data from JS to specific Flash property which flash is "watching" for changes.
<flash code>
var testProp = "jos"
this.watch("testProp",alert);
function alert(id, oldval, newval) {
trace(id + ": " + oldval + " > " + newval);
return newval
}
testProp = "sam"; // this will trigger the alert function
stop();
</code>
To send data the other way, you could continue to use the FSCommand or the getURL system, depending on the browser combo...
<JS code>
// setup some var to hold the DOM value/id of the swf movie
movie.SetVariable("/:testProp","new val");
// the "/:testProp" is the 'old' style of targeting properties in flash. I don't know if the new
// dot syntax works or not.
</code>
So, i think that should all be good.
Your previous message with all the examples of the POST contents was _extreamly_ helpful. In fact i think you should add that to the FAQ or documentation someplace, as it makes it very clear what the message's traveling to the server look like.
So, now for the new questions! How are the kn_from paths constructed? In the example you gave, you created a tunnel using the following string (missing the POST/host etc data):
"kn_response_format=flash;" +
"do_method=route;" +
"kn_from=/who/jos/s/24/kn_journal"
Can the client define the kn_from paths? Or does the path get created by the server? I've used this example and gotten it "working" (with several caveats), but i'm not really sure what the "/who/jos/s/24/kn_journal" means...
So, i've built a really basic tool...
http://www.trapeze.com/r_and_d/pubsub/t2.fla
and
http://www.trapeze.com/r_and_d/pubsub/t2.swf
(note - its looking for the server on localhost on port 8008)
...for doing experimentation with the python pubsub.py server. It connects, and can send info. I've yet to get info back, other then notification that i've established a route. I have sent a message to a /what/chat app running in a browser from it, which was pretty cool. The only thing i've changed in the pubsup.py file is:
in SimpleTunnel (ln ~481)
<code>
def encode(self, dict):
"""Same as ev_encode, except including the count and
separators, so it can actually be sent on a tunnel."""
# str = self.ev_encode(dict)
str = self.ev_encode(dict) + chr(0)
return "%d\n%s\n" % (len(str), str)
</code>
so i'm just tacking on an extra null byte (chr(0)) to the string to force flash to fire the onData handler. Not pretty, but it works for this...
So, to reiterate, i can do a do_method=route;kn_from=/who/jos/s/24/kn_journal and get a response from the server.
I can do a do_method=notify;kn_to=/what/chat;kn_payload=hello and get it to show up in a browser running the chat1 app.
Thats it so far, but good to get some progress! Again, the thing that i'm a bit unclear about now, is the paths used in kn_to and kn_from. I also have to dig into the python to figure out where it receives the POST data, so i can try to figure out why it drops the connection ...
Cool!
jos
P.S. -- I should also quickly say how the flash app works too! Sorry! The bottom box is where you enter the info - just the
"kn_response_type=simple;do_method=route;kn_from=/who/jos/s/24/kn_journal"
type stuff - it automagically adds the POST headers to that.
The upper box is where it echos what you are sending and any info you get back from the server...
-------------------------------------------------------
This SF.net email is sponsored by: ObjectStore.
If flattening out C++ or Java code to make your application fit in a
relational database is painful, don't do it! Check out ObjectStore.
Now part of Progress Software. http://www.objectstore.net/sourceforge