How does ChatRoulette work – the RTMFP protocol

Disclaimer – I’ve never used chatlroulette and have no intention of starting. But I was curious about the technology under it. Has Flash finally enabled some way of direct peer-to-peer streaming of data? And it appears that this is the case.

The RTMFP protocol is a version of Adobe’s earlier streaming protocol called RTMP. RTMFP uses UDP datagrams, which are not guaranteed to be delivered, as TCP ones are. But this is fine for live streaming apps, since data from a second ago is already outdated.. so why bother trying to guaratee delivery and all that overhead.

But the real magic with using udp is – firewall transparency. Since firewalls usually allow most outbound traffic through without much harassment (at least for home users), inbound is another story. NAT enabled routers are not even able to allow inbound connections without some finagling, since it has no idea which local machine to send the connection request to.

UDP doesnt have all the extra error checking headers etc, so it’s pretty trivial to trick it into “faking” a connection across firewalls, but having computers at both ends of the connection intiate a connection about the same time. A third-party middle server is normally used to coordinate the setup and timing of the attempt to connect in this manner. The router will see outbound packets to an ip and port, and then see packets coming back from that same ip and port… and will assume they are responses to the request, thus forwarding them on to the internal computer. This can be done from both ends at the same time, thus both ends can be behind firewalls etc. You’ll definitely get a few bad packets bouncing off the firewall until both ends get their business straigntened out, but after this everything will usually just work.

TCP, on the other hand, has headers which keep track of a bunch of things, like sequence etc., so when these headers are not correct the router will discard them as being bad.

I did some research some years ago to see if it would be possible to do this same trick of “faking” a connection (called “connection splicing”) with TCP as well. The only way it *might* be possible is to have the third party server doing some illegal packet manipulation to fool the firewalls. I never decided if was truly impossible or not, but at minimum it would be tricky. I did manage to find one other discussion about this, appears to still be around:

Back on topic – the reason I dug back into this today was I was curious if Silverlight has any provisions for supporting something like the RTMFP protocol, and thus allow direct p2p connections. From what I can tell, it does not currently support anything like this.

Update- apparently chatroulette went offline recently and displayed the message “chatroulette rtmp connection failed”, so there was a spike in search traffic to this page for that phrase. Short answer: yes, this means chatroulette is offline, just wait for it to come back!

Async javascript loading for reduced page load time

Many of my websites have the standard addins for integrating with the rest of the world- the gadget, the facebook like button, etc. A number of them also use google maps. Each of these includes a javascript file from a remote source, which normally will slow down the load time of your pages. Google fixed their analytics scripts some time back to allow loading them asynchronously, so the page is not paused while waiting for it to load. Strangely, a lot of scripts don’t yet support this, and I’m seeing in google webmaster tools that the calculated load time of my pages has suffered as a result. What should be a tiny page that loads in literally milliseconds, is now a 3 to 5 second loading affair.

After some research, it looks like this is not a simple task to undertake. There are a number of ways to load a script async, but each has a set of drawbacks. This seems to be a great overview of the various methods currently avaialble: . I’ve seen that html5 also includes direct support for allowsing async loading of scripts, so maybe eventually this will no longer be a problem, but for now it’s a pretty big headache.

As time permits (or, when I get the chance to delegate it), I’m planning to try the solution listed on that linked page and see if addthis, facebook, google maps, perhaps even adsense, and even a wufoo form can perhaps be loaded in this async manner. I’ll report the progress here.

Orchard multitenancy configuration

Am now successfully running multiple sites on a single instance of Orchard (this one). Can’t really divulge what they are, but I will comment on the configuration- when making a new tenant, make sure you have no spaced in the name. It doesn’t fail immediately, but does a few steps later. The solution requires – 1. shut down the orchard website instance 2. open the tenants subfolder in the app_data and find the offending folder with spaces in the name, and delete it. 3. restart the website.

Note that even if you abandon an existing “spaces in name” corrupted attempt, it will still blow up every time you try to create a new one until this is resolved. And, if you don’t shut down the site first, it will keep recreating this messed up folder. fun times.  

torsion bar valve springs

When I’m running, I get lots of weird ideas. Today, I thought, why not use torsion bars for valve springs in engines, instead of the usual coil spring? Benefits should include- less moving mass, adjustable pre-load, and… well that’s all.

So, this falls into the “new-old” ideas category – apparently was done as far back as the 50’s- even this clunker had them –

And some F1 cars and bikes have used them with good effect. So, good new-old idea 😉