Skip to main content
Ben Nadel at the jQuery Conference 2009 (Cambridge, MA) with: Karl Swedberg
Ben Nadel at the jQuery Conference 2009 (Cambridge, MA) with: Karl Swedberg ( @kswedberg )

Pusher.cfc - ColdFusion Component For Realtime Notification With HTML5 WebSockets

Published in , Comments (24)

Lately, I have been playing around a lot with a service called Pusher. Pusher provides realtime push notification services for your web applications using HTML5 WebSockets (or Flash for non-compatible browsers). While using the Pusher service is extremely simple, digitally signing your HTTP request is not; I've had a good deal of back and forth with the Pusher support team, trying to squash a few bugs in my code. Having finally figured out where my HEX-encoding was failing, I figured I would roll this up into a ColdFusion component and a tiny demo project that anyone could download.


The code for my Pusher.cfc ColdFusion component and my demo application is available on my Pusher.cfc project page. If you'd like to try the online demo, click here.

Reader Comments



People who have seen me play with the Pusher stuff have suggested that I look into BlazeDS - but I kind of love the idea of "as needed" communication rather than long polling.


Ben, do you think could CF Gateways could perform a similar service as Pusher? Have you heard of anyone using CF Gateways with the HTML5 WebSockets?

We have a gateway set up to push IM messages to users and are intrigued at the possibility of doing the same thing with HTML5.



I don't know how true this is anymore; but, I think at one time, pretty much all "Gateway" activity in ColdFusion was Enterprise edition only. As such, I never really played around with any of the gateway stuff. I think that may have been changed in recent editions of ColdFusion (I think Standard can do more gateway stuff).

I'll have to look into it one day.


You're right and I always forget that. That probably explains why information for CF Gateways is so hard to come by.



Was the encoding issue the root cause of the 401 Unauthorized errors you were seeing? I have been busy with other projects lately and I haven't really had time to work on my pusher app. Looking forward to playing with it more.



Yeah it was. In 90% of the cases, the hex encoding resulted in the needed 64 characters. In 10% of the cases, it only resulted in 63 characters and I needed to pad with one zero... which I was foolishly padding on the *wrong* side of the encoded signature :(


Looks cool, but I can't use it - all of my servers are Windows; with all the little I know about VirtualBox stuff, it seems like too much overhead for me to play with at this time.


@Ben Nadel,

Well in that case I think you are going to love this. This one looks very easy to implement.

Go to and download the community edition

To Run the server
On Unix execute,
on Windows runExamples.bat.

This will start StreamHub at http://localhost:7979/ -
open that page in your browser to view the examples.

Im on a Mac and I don't know how to execute the script :(

Im going to try it on a windows box I will let you know the results.



That also looks very cool. I'm really digging the realtime notification mindset. Now, I just gonna figure out what some of the better practices are.



On a Mac, it should be:

> cd /wherever/you/stored/the/sh/file
> ./

Or just:

> /wherever/you/stored/the/sh/file/



@Joe Rinehart,

Thanks Joe. I actually got it to run.

I was looking into the JAVA samples they have. Im trying to send msgs to the StreamHub Server via CFC using the java API.

If anyone has any idea on how to implement this I'll truly appreciate it.


Hey Ben - I was playing around with Pusher and was alerted to

You may want to check it out.

Way easier to use than Pusher (no need to complex key encoding/encryption) and works across all the major browser without needing Flash socket fallback.



Looks cool. It appears there are quite a number of HTML5 Push services now. This stuff is really catching on (and getting easier and easier to implement).



I've tried to run the demo on your site and also download it and run from my system with my own API key, etc. and connecting to pusher just stays there. The connection_established event seems to never get fired. If I bypass the server connection test and post a message to the server, I see that the message is posted successfully, but none of the triggers are fired. I thought maybe it was my browser, so I updated to the latest version of Safari and still nothing, both on your demo and my locally installed demo. I'll keep trying to figure it out, but any help would be greatly appreciated. I know it's probably something really stupid and obvious that I'm missing.



I've definitely seen the Pusher API just seem to give out from time to time. I just tried it on Safari on Mac (for the first time - was on a PC when I wrote this post) and it worked. Glad it finally got working for you.


Have you tried using web sockets tied in with cfthread? In other words... Fire off 100 threads or so doing long requests, as each one finishes it pushes some data to the browser.

Would that work?



I've played around with integrating Pusher into jQuery as part of a long-running AJAX request:

Basically, I added an "update" callback for the $.ajax() method which allows communication to take place after the AJAX request has completed.

Now, granted, in that example, I am not making any communication in an actual CFThread - but there's not that much difference to do something from within a CFThread. At the end of the day, you'll just be posting to the PusherApp API using CFHTTP.



Have you worked with the presence and private channel auth at all with pusher? I exchanged an email with Bradley Lambert who said he's not really worked with it since he posted the cfc so it's probably his pusher-cfc will probably not get developed further. Wonder if perhaps we could expand on it to provide the presenceAuth and and socketAuth capabilities like the php library has in your cfc.

I've personally been struggling with the SHA-HMAC256 signing of the JSON message, or I'd add myself. (CF9 Standard).

I'm seriously about to do a cfhttp call to the dang PHP component to work around for now…(ugh) but at least it's working.

It's simply a matter for presence to sign

<socket_id>:<channel_name>:<JSON encoded user data>

and return Like

{"auth":"278d425bdf160c739803:afaed3695da2ffd16931f457e338e6c9f2921fa133ce7dac49f529792be6304c","channel_data":"{\"user_id\":10,\"user_info\":{\"name\":\"Mr. Pusher\"}}"}

I do see the merit behind this process and notice the authenticated private channels are absent in other push "services" out there hence my continued interest with the Pusher service as an option for a project I'm working on.

The details for pusher's auth signature is here:



I believe in love. I believe in compassion. I believe in human rights. I believe that we can afford to give more of these gifts to the world around us because it costs us nothing to be decent and kind and understanding. And, I want you to know that when you land on this site, you are accepted for who you are, no matter how you identify, what truths you live, or whatever kind of goofy shit makes you feel alive! Rock on with your bad self!
Ben Nadel