Saturday, October 6, 2012

Android + Erlang for Great Good: An Introduction

I've recently begun working on a multiplayer Android game that will communicate with an erlang server.   The erlang server will contain at least 2 endpoints, a REST account manger and a Websocket which will push erlang server events from the server engine and receive all player commands.

My experience in both erlang and android development is extremely limited, essentially I've read (some of) the manual and written a few lines of demo/tutorial code in each.

I began by looking for a proper web server for erlang.  I reviewed the following:

  1. Webmachine.  Great implementation of a RESTful server, layered on mochiweb.  Their RESTful diagram is a great resource for people wanting to understand REST better.  No built in support for Websockets as of yet.
  2. ChicagoBoss.  Very new, looks extremely interesting.  An MVC framework for erlang, it utilizes Django style templates which are actually compiled into erlang bytecode for speed.  Recommend reviewing it if you want to write a standard MVC application or a RESTful webserver for a client side MVC framework.  Supports Websockets via Cowboy. 
  3. Cowboy.  A brand new http server in erlang.  Cowboy is technically more of a tcp/ip connector pool/manager with out of the box support for http, https, REST, and Websockets. 
After doing a POC of a websocket implementation in ChicagoBoss I realized that most of what I needed was in Cowboy and ChicagoBoss, while cool, didn't really add all that much to the equation. It's a great framework for an MVC application, but doesn't really fit my use cases.

One item I lost when I removed ChicagoBoss was the transparent encoding/decoding of json that make RESTful interfaces in ChicagoBoss so simple.  After a bit more searching I found jiffy which appeared to suit my needs.  It transforms json objects into erlang proplists.  Additionally its written in C and utilizes binary strings for improved performance.

On the Android side I looked into using phonegap or appcellerator or just an HTML 5 webapp, and I decided that I wanted to actually learn to code on the Android platform.  So the client will be Java targeting Froyo (API 8).

Before continuing you'll want to get Erlang installed and working on your system.  For Ubuntu I recommend this gist.  You'll also want to familiarize yourself with rebar, the build system for erlang.

Erlang server source code at brocksamson/my_game

Newer posts:

1 comment:

  1. i see this is an older blog post .Are you still working on this configuration for your game project ( android + erlang)

    ReplyDelete