communicating arbitrary data via rtfmp (pt. 1)

hi there and a happy new one (can you still say that on january 7th?).

since i am supposed to work on my bachelor thesis it got quiet around here.
but when i read about the new stratus service a few days ago i couldn’t wait to get my hands on it. for those who haven’t heard of it: it’s a service which provides information to the flash player/air instance to communicate peer-to-peer to another remote instance. before this stratus beta started there was no way of using the new rtmfp (an udp-based network protocol which came with fp10) at all.

after creating a small one-way microphone-chat i wondered how to exchange arbitrary data between the peers. the adobe stratus site reads about the use of rtmfp: “A video chat application, Multi-player game, Voice Over IP” - ok, so while the first and last of that list is in fact quite the same (NetStream.attachCamera() and attachAudio()) and greatly covered by jozsef vass’ article “Stratus service for developing end-to-end applications using RTMFP in Flash Player“,  there are no resources about how to exchange data other than video and audio. or are there?!

in the fp10 api i stumbled upon NetStream.send() which was previously used to communicate with the FMS only, i guess. so like with ExternalInterface you can call functions outside of flash’s sandbox: so not javascript this time, but actionscript on other peers. (:
to be more specific: you call functions on the NetStream.client which is of type Object - so you can put there whatever you want. to a function of this client-object you can pass as many arguments as you like, as long as they are of native types.

you’ll find a short example after the jump:

the premise of this example is an established rtmfp-NetConnection (how to do so you can read in vass’ article linked above):

on the sending peer:

var netStream:NetStream = new NetStream(netConnection, NetStream.DIRECT_CONNECTIONS);
netStream.send(”receiverFunction”, “foo”);

on the receiving peer:

var netStream:NetStream = new NetStream(nc, id_of_sending_peer);
var clientObj:Object = new Object();
clientObj.receiverFunction = function(arg1:String):void{ trace(arg1); }
netStream.client = clientObj;

so every time the sender’s NetStream calls send(”receiverFunction”, …) the receiving peer outputs the incoming argument in the console.
but that works for native types and objects only. that reduces the communication to only Booleans, ints, Numbers, Strings, Vectors and Arrays (and the others i have forgotten).

in the second part of this article i’ll show you how to send objects of your custom classes back and forth between the peers.

This entry was posted in Actionscript, Networking. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

3 Comments

  1. Posted January 24, 2009 at 3:02 am | Permalink

    One note - it’s been possible to use RTMFP using Cocomo since November - check it out : http://blogs.adobe.com/collabmethods/2008/12/try_rtmfp_and_clienttoclient_d.html

  2. Dmitry
    Posted May 5, 2009 at 5:31 am | Permalink

    Could you post your source code for this article? Thanks.

  3. kris
    Posted May 11, 2009 at 3:39 pm | Permalink

    sources are up now.

One Trackback

  1. By communicating arbitrary data via rtfmp (pt. 2) on January 19, 2009 at 10:24 pm

    [...] flash, actionscript, pixel bender and blah.. you know the drill Skip to content About « communicating arbitrary data via rtfmp (pt. 1) [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*