Flash and pubsub...

"Adam Rifkin" <[email protected]>
Newsgroups gmane.comp.web.mod-pubsub.devel
Message-ID <[email protected]>
Hi Jos,

Excellent work!!  In response to your questions...

> Now, it connects fine to the server (ya!), however, when i get to
> making a request to the server, i'm not really sure what i'm doing.  ;)

Well, please do keep asking questions.  We love to answer questions.  :)

> You can see the 'req' string is a HTTP string representing a POST
> request. What i'm unsure of, is _where_ this request should be sent,
> and how i do something basic like echo back from the server, so i
> can tell if i'm doing it right...
>
> If i leave the line "POST /what/url HTTP/1.0\n" to point to the root -
> "POST / HTTP/1.0\n", what do i need to add to the name: value pairs to
> get some data echo'd back? or, perhaps, this is enough, and its simply
> that there is no null value tacked on to the end to fire the onData
> handler?

To send a request to a PubSub server, use something like this:

"POST /kn HTTP/1.0\r\n" +
"Host: localhost\r\n" +
"Content-Length: " + myContent.length + "\r\n" +
"\r\n" +
myContent

Where myContent might be for example

"kn_response_format=flash;" +
"do_method=route;" +
"kn_from=/who/jos/s/24/kn_journal"

to set up a streaming flash-formatted "tunnel" (note that kn_response_format=flash won't work until you add support for it to the server; to get started you might use kn_response_format=simple instead.

To establish a subscription (say, to "/what/chat") send a request like this:

"kn_response_format=flash;" +
"do_method=route;" +
"kn_from=/what/chat;" +
"kn_to=/who/jos/s/24/kn_journal"

Then to publish to that topic, send a request like this:

"kn_response_format=flash;" +
"do_method=notify;" +
"kn_to=/what/chat;" +
"kn_payload=Hello%20World%21"

Now, about that "kn_response_format=flash": it could be identical to "kn_response_format=simple", but it would need to send an additional NUL byte after each event serialization so XMLSocket will notice the new data.

Note that event serializations can include embedded NUL's, so more than one XMLSocket read may be necessary to read a full event.

   Adam



-----Original Message-----
From:	hyakugei [mailto:[email protected]]
Sent:	Fri 5/16/2003 7:20 AM
To:	Adam Rifkin
Subject:	Flash and pubsub...

** I tried to post this to the email list with no success 
** If you could forward it, that would be great, thanks! 

Hey all, I've just started to look at the python pubsub server working with Flash.

Looking at Scott's code (from his site: http://www.scottandrew.com/main/2003_01#a000494), i've got a server running on my local box. I've modified the code like so:

<code>
socket = new XMLSocket();
socket.onConnect = function (success){
    if(success){
        trace("Connection UP");
    }else{
        trace("No Connection");
    }
}
socket.onClose = function ()  {
    trace("Connection Closed");
}

socket.onData = function (src)
{
   trace("\ndata:" + src);
}

if (!socket.connect("localhost", 8008))
{
   trace ("connect: Connection failed!")
}

var req = "POST /what/url HTTP/1.0\n" +
   "User-Agent: FlashMX Client (Win2K)\n" +
   "Host: localhost\n" +
    "kn_response_format: simple\n" +
   "Content-Length: 12\n" +
   "Content-Type: text/plain\n\n" +
   "Hello World!";

var xml = new XML(req);
trace(xml);
socket.send(xml);
</code>

Now, it connects fine to the server (ya!), however, when i get to making a request to the server, i'm not really sure what i'm doing.  ;)

You can see the 'req' string is a HTTP string representing a POST request. What i'm unsure of, is _where_ this request should be sent, and how i do something basic like echo back from the server, so i can tell if i'm doing it right...

If i leave the line "POST /what/url HTTP/1.0\n" to point to the root - "POST / HTTP/1.0\n", what do i need to add to the name: value pairs to get some data echo'd back? or, perhaps, this is enough, and its simply that there is no null value tacked on to the end to fire the onData handler?

Anyway, having fun playing with it!

jos

-- 
Jos Yule

EWACT (employee without a cool title)

Trapeze
2 Berkeley St. Suite 305
Toronto, ON, CAN

http://www.trapeze.com
mailto:[email protected]
phone: 416 601 1999 x227



------ Refers to Scott's code:

http://www.scottandrew.com/main/2003_01#a000494

XMLSocket

Speaking of Flash...I've been messing around with Flash MX and its support for persistent, two-way streaming connections via the XMLSocket stuff. Interesting point: you can do arbitrary HTTP requests by shoehorning the text of the request into a malformed XML document:

socket = new XMLSocket();

socket.onData = function (src)
{
    trace("\ndata:" + src);
}

if (!socket.connect("my.example.com", 80))
{
    trace ("connect: Connection failed!")
}

var req = "POST /mod_pubsub/demo HTTP/1.0\n" +
    "User-Agent: FlashMX Client (Win2K)\n" +
    "Host: my.example.com\n" +
    "Content-Length: 12\n" +
    "Content-Type: text/plain\n\n" +
    "Hello World!";

var xml = new XML(req);
socket.send(xml);

Through this, I've been able to hook up Flash MX to a KnowNow event router (the same should work for mod_pubsub, but I haven't tested it yet) with varying degrees of success. A small sticking point seems to be that any returned data has to be terminated with a null character (like "%00") or the data handlers won't fire. But it's encouraging to know that you can effectively speak HTTP over XMLSocket without having to speak XML.




-------------------------------------------------------
Enterprise Linux Forum Conference & Expo, June 4-6, 2003, Santa Clara
The only event dedicated to issues related to Linux enterprise solutions
www.enterpriselinuxforum.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.