James Clarke & Notes

Java FEC Example

I’ve written an example on using the Java FEC Library by Onion Networks. This had been on my TODO list for quite awhile, since I had trouble using the library during development of MSync.

When I was doing work on my multicast rsync application, MSync, I was having trouble understanding and using the Java FEC Library from Onion Networks. I gather that other people may be suffering from the lack of examples available on the Internet, so I’ve created one.

Code

My Java FEC example is commented and demonstrates how to encode a byte array and decode it again from a subset of the encoded data. It should be quite simple to adapt the code to encode a file and transmit it over UDP.

Please note I am in no way affiliated with Onion Networks, nor had any part in writing the Java FEC library. If you are interested in how forward error correction works you should read Effective erasure codes for reliable computer communication protocols by Luigi Rizzo.

Running

Place all the jars from the Java FEC Library and fec.properties into lib/. The properties file tells the library to use pure codes rather than native codes.

$ export FEC_CP=.:lib/concurrent-jaxed.jar:lib/log4j.jar:lib/onion-common.jar:lib/onion-fec.jar
$ javac -classpath $FEC_CP JavaFecExample.java
$ java -classpath $FEC_CP JavaFecExample
Source and Received Files are equal!

The code is avialble at javafec-example on GitHub.

blog comments powered by Disqus