Lolrus.org

This is a header that goes on every page.

Cometd and me

February 08, 2008 at 09:01 PM | categories: Uncategorized | Comment

I kind of go on tangents when I do personal projects. First my goal was to make a poker game for bots to play... then somehow it diverged to making an ajax client.... somehow it diverged after that to use comet/cometd to do it... and then finally I decided to rewrite the cometd-twisted for my own evil.

Basically, for games and such, the bayeux protocol is a good place to start, but all the publish/subscribe stuff is superfluous. I basically just wanted to use the heart of the protocol and the ability to use the existing JavaScript libraries.

I think what I did is pretty cool. Basically, I made it so when a client connects it spawns a new client class. Then when they subscribe to a channel it makes a ChannelSubscription class. The messages are routed through this. Each ChannelSubscription behaves as a logical connection to the client such as a Protocol class with Twisted would. In fact, there's about 3 lines of difference between my TCP layer for my poker client and my comet layer now. It's pretty cool.

I set it up so that authentication and such would happen one level on top of the Bayeux protocol to allow for more customizations. It doesn't matter whether or not they connect.

I have half of an ajax poker client written for my server with this, but it's basically just a proof of concept that this works. I think I'm going to write a blackjack server too to allow for easier testing, and a better demo for when there aren't people to play against. It's simpler, and I already have most of the code done in Ruby from a long time ago... I just need to port it over Python.

Anywho... I'm calling my cometd server ucommet. Why? I couldn't think of anything better.

The source is here for all the stuff (you want ucommet.py and possibly tabled.tac to see how it's used)

you can do a "svn co http://svn.lolrus.org/dpoker/trunk dpoker" to get my poker tree.

You'll need twisted.web2. If you have twisted 2.5, actually might have to get the SVN version. The apt-get seemed to get a working version for me in Ubuntu, but on my Gentoo server it was a whole different story :(.

I'm going to be in Prague with some friends for the next three days (my last days in Europe before I come home). Then once I get back to the states, I'm going out to Cali for a day or two for an interview. It's been too long since I've had a burrito or a double-double. So what this means is I probably won't have time to work on this for the next week or two.

blog comments powered by Disqus