GitHub Documentation

Raspberry PI and Colyseus ( and Haxe)

  • Raspberry PI & Colyseus ( & Haxe )

    Currently there are two basic ways to deploy my Colyseus server:

    • (Virtual) Host on premise or in the cloud
    • Docker container running on premise or in the cloud

    For my Console system I wanted to run Colyseus and Haxe on a Raspberry PI.
    You could use this as a low budget computer for testing purposes or use port forwarding on your router to host it to the rest of the world.

    The steps below could be used to create a nodejs server and you can avoid all the extra steps to get haxe working.

    For small multiplayer games or for turnbased/idle games this would be a cheap way to run a server from your home.

    The procedure for a Virtual Raspberry PI (VirtualBox/XenServer) is much simpler because the x86 can work with lix.
    Unfortunately I haven't managed to get lix working on the real (ARM) hardware. It defaults to an incompatible distribution.

    If anyone knows how to tell lix to get the ARM based executables that would make this procedure a lot easier

    Installation Steps:


    • Raspberry PI B v1.2 : 1GB Ram, 4x 1.2 Ghz Cores
    • Stretch image 2018-11-13-raspbian-stretch from
    • Use Win32DiskImage/RUFUS to write the image to a 16GB SD card. The haxe software that we will install brings it to 14 GB!

    Boot raspbian (default it will use DHCP to get an IP address)
    Open terminal : sudo su - (Become root)

    vi /etc/ssh/sshd_config 

    change permitRootLogin to : permitRootLogin yes

    change password for root : passwd root

    Allow putty / ssh into the PI

    systemctl enable ssh
    systemctl start ssh


    apt update
    apt upgrade

    restart the PI

    Get the IP address:

    ip addr show      

    login as root to do the (remote) installation

    cd /root
    #curl -sL | bash - # used for x86 version of pi
    curl -sL | bash -
    apt-get -y install nodejs
    node -v
    npm -v

    You can install the node stuff for Colyseus and run the NodeJS version.

    But I wanted HaXe so these are the steps we need to make before we can compile the neko and haxe versions

    If you are on x86 versions you can use the serjek example github files and use ' lix download' to download the binaries.

    But for now I had to compile the ARM versions:

    # ---------------
    # Neko / HaXe / Colyseus-hxjs 
    # ---------------
    # base software packages  
    # execute line after line (do not copy-paste-run!)
    mkdir -p ~/Development/haxe/{dev,lib,source}
    cd ~/Development/haxe/source
    apt-get install -y build-essential git cmake
    apt-get install -y libgc-dev libgc1c2 libpcre3 libpcre3-dev
    apt-get install -y apache2-dev libmariadb-client-lgpl-dev-compat    
    apt-get install -y libsqlite3-0 sqlite3 libsqlite3-dev    
    apt-get install -y libgtk2.0-dev
    apt-get install -y libudev-dev
    apt-get install -y libasound2-dev
    apt-get install -y zlib1g libmariadb2 libmbedtls-dev libmbedcrypto0 libmbedtls10 libmbedx509-0
    apt-get install -y m4 ocaml ocaml-native-compilers libpcre-ocaml-dev libextlib-ocaml libextlib-ocaml-dev opam
    apt-get install -y openssl libssl-dev 

    Interactive setup/install:

    opam init
    ocamlc -config|grep arch # should be arm 
    opam install conf-m4 ocamlfind sedlex depext xml-light extlib rope ptmap sha

    We are ready to install neko and haxe:

    export HAXE_VERSION='4.0.0-rc.2'
    export NEKO_VERSION='v2-2-0'
    cd /root
    eval `opam config env`
    #Neko install
    git clone --recursive -b $NEKO_VERSION
    cd neko 
    mkdir build
    cd build
    cmake -DRELOCATABLE=OFF ..
    make install

    Test the neko by typing in neko and check that the version is 2.2.0

    # haxe install
    eval `opam config env`
    cd ~/Development/haxe/source
    git clone --recursive -b $HAXE_VERSION
    cd haxe
    make tools
    make install  

    haxe --version # should give you 4.0.0-rc.2

    Setting up the libraries to run the examples

    haxelib setup
    # default /usr/lib/haxe/lib
    # yarn
    npm i yarn -g
    # Get Haxe Libraries
    cd /usr/lib/haxe/lib
    # haxelib git colyseus-hxjs
    git clone

    Unfortunately I'm not good enough with haxe and lix libraries and I needed a hack to get
    the colyseus-hxjs library to work with the compiled ARM versions.

    Apparently the required versions are different from the default haxelib installations.
    Since I know that the lix steps worked for x86 installations I used a mix of installation steps to get it to work.

    npm i lix -g
    cd /root
    git clone
    cd /root/colyseus-hxjs-examples
    # We are still going to download the latest haxe_libraries but we are using the haxelib versions later
    lix download
    haxelib install tink_core
    haxelib install tink_lang
    haxelib install hxnodejs
    # Now we need to copy some of the /root/haxe/haxe_libraries to the haxelib libraries:
    mkdir -p /usr/lib/haxe/lib/colyseus-hxjs/git/src
    cp -r /root/haxe/haxe_libraries/colyseus-hxjs/0.0.0/github/*6  /usr/lib/haxe/lib/colyseus-hxjs/git
    mv /usr/lib/haxe/lib/colyseus-hxjs/git/*6/src  /usr/lib/haxe/lib/colyseus-hxjs/git/src
    cp -r /root/haxe/haxe_libraries/hxnodejs/6.9.1/haxelib/src/ /usr/lib/haxe/lib/hxnodejs/10,0,0
    echo "git" > /usr/lib/haxe/lib/colyseus-hxjs/.current
    haxelib list

    With these hacked haxe libraries we can then run the steps to create node versions from the haxe code:

    haxe server.hxml
    cd bin/server
    node index.js

    You can now tell your client to connect to the examples.

    My pre-alpha Stencyl Extension Server was used by myself to run the TicTacToe game.

    For that I installed a webserver on the PI and uploaded both the server code and the client code to the Raspberry PI:

    # Apache WebServer
    apt-get install apache2
    systemctl enable apache2

    Copy your project to /var/www/html
    Visit your game with a browser to the following URL: http://raspberry_pi_ip_address

    You can use win32diskimage to create an image from the SD card as a back-up.

  • Currently trying this right now on my Android TV box converted to Armbian Debian 5.75 ($22 US, Arm64 @ 2.0gz x4, 4gb ram / 32gb rom, 1gb Ethernet)

  • neko compiled with no problem but haxe puked during make. Likely the differince in Armbian vs Raspbian distros but I had to install camlp4o (sudo apt-get install camlp4-extra). Haxe installed fine afterwords. Working on the rest now...

  • currently stuck with the following error when running haxe server.hxml

    /usr/lib/haxe/lib/tink_core/1,24,0/src/tink/core/Error.hx:116: characters 9-21 : Class<Std> has no field downcast
    src/MainServer.hx:3: characters 8-30 : Type not found : colyseus.server.Server

  • what does ' haxelib list ' show?

    I had to use a mix of steps ( haxelib install and copying files) before haxe server.hxml could find all types.

  • ~/colyseus-hxjs-examples$ haxelib list
    colyseus-hxjs: [git] haxelib.json src extraParams.hxml
    hxnodejs: [10.0.0]
    tink_core: [1.24.0]
    tink_lang: [0.6.2]
    tink_macro: [0.17.7]
    tink_priority: [0.1.4]
    tink_syntaxhub: [0.4.3]

  • @closetmonkey
    Hmm that is a strange output of haxelib list on colyseus-hxjs

    From memory (I don't have access to it now since I'm at work) the colyseus-hxjs should only have one version behind it :
    colyseus-hxjs: [git]

    this was used to tell haxelib what version it should use:
    echo "git" > /usr/lib/haxe/lib/colyseus-hxjs/.current

    what is the contents of your .current file?!

    Maybe you just edit the /usr/lib/haxe/lib/ (or your own haxelib path) /colyseus-hxjs/.current and make sure it only has the git in it?!

  • @mdotedot said in Raspberry PI and Colyseus ( and Haxe):

    ... /usr/lib/haxe/lib/colyseus-hxjs/.current

    '/usr/lib/haxe/lib/colyseus-hxjs/.current' has one line with the contents of 'git'. Interestingly, haxelib.json src extraParams.hxml is the directory contents at /usr/lib/haxe/lib/colyseus-hxjs/.

    ~/colyseus-hxjs-examples$ ls /usr/lib/haxe/lib/colyseus-hxjs/
    extraParams.hxml  git  haxelib.json  src

  • Unfortunately I can't confirm now on my system, but you might try to move the contents of that hxjs directory to the [git] (or copy)
    So that /usr/lib/haxe/lib/colyseus/-hxjs/git has the src, haxelib.json, and extraParams.hxml

    And then try again haxe server.hxml

  • That did it, however, I now get the following errors

    ~/colyseus-hxjs-examples$ haxe server.hxml
    /usr/lib/haxe/lib/tink_core/1,24,0/src/tink/core/Error.hx:116: characters 9-21 : Class<Std> has no field downcast
    src/server/rooms/StateHandlerRoom.hx:5: characters 1-51 : Module colyseus.server.schema.Schema does not define type MapSchemaUtil
    src/server/rooms/StateHandlerRoom.hx:5: characters 1-51 : For function argument 'handler'
    src/MainServer.hx:7: lines 7-41 : Defined in this class

  • Not sure if you are mixing libraries. The stuff that I rely on is from serjek and was based on 0.10 release. There is now a 0.11 release so I hope you didn't load any of that?!

  • From my setup:

    root@raspberrypi:~/colyseus-hxjs-examples# haxe -version


    root@raspberrypi:~/colyseus-hxjs-examples# haxelib list

    colyseus-hxjs: [git]
    hxnodejs: [10.0.0]
    tink_core: [1.23.0]
    tink_lang: [0.6.2]
    tink_macro: [0.17.7]
    tink_priority: [0.1.4]
    tink_syntaxhub: [0.4.3]

    root@raspberrypi:~/colyseus-hxjs-examples# cat src/colyseus/server/schema/Schema.hx | grep MapSchemaUtil

    class MapSchemaUtil {

    Your tink_core is different than mine. Don't know if that is the only thing that is different?


© 2021 Lucid Sight, Inc