Matt Tuttle


Haxe Networking and Bonjour

Haxe Networking and Bonjour

I've been working on a party game for the last few months that requires local networking between iOS and Android. The only problem is that I didn't want users to have to type in ip addresses. Enter the world of zero configuration networking...

Bonjour has been around for quite a while and primarily works on iOS and OSX, although Apple has provided a Windows library as well. Essentially a program publishes a services over the network that is available to find from any computer on that network. Another running program can then broadcast out a request to find certain types of services and resolve them. If none are found, the program can choose to stop looking or send out another request.

This is all well and good but Android doesn't have support for Bonjour. Instead someone created jmDNS which is a Java implementation that can talk with Bonjour services, with some minor differences. So now I knew which libraries to use but neither one of them works with Haxe which is the programming language I prefer.

With some help from hxcpp I was able to glue the two libraries together into a single class that can be used on multiple platforms. This solved my problem of finding devices over the network but what about connecting them together?

Haxe has basic socket connection classes, UDP will be in 3.1.0, but no major networking library (that I'm aware of). Using Python's twisted framework as inspiration I decided to create hxnet. It has simple Client/Server code for both TCP and UDP as well as basic protocol classes for RPCs and Telnet.

The Bonjour class is included in hxnet and it should be flexible enough to add protocols like HTTP, FTP, etc... I'm not sure I'd consider it production level code yet but it's solid enough for me to build my game with it. If you want to give it a shot the code is on GitHub and feel free to create pull requests if you find bugs or code up a crazy new feature.

Posted in General

Tags: Haxe, networking, twisted, udp, tcp, hxnet

comments powered by Disqus