Networking made "easy": Network Objects library

Hello,
After working with processing’s built-in network library for some time, I noticed that there were certain aspects of the library that made managing Clients and sending Objects over the network unintuitive, cumbersome, or repetitive. This inspired me to make a wrapper class that uses the built-in network library to easily manage connections and send and receive Objects over the internet. The project eventually became my Network Objects Library, which is posted publicly on Github.
The premise of the library is that all Objects you want to send over the network implement the Packet interface, which requires that the Object can be converted to and constructed from a byte[]. A static class ByteOps, short for Byte Operations, has methods that can convert all primitives and Strings to and from a byte[], and can modify byte[]s by combining, slicing, or shortening them. This facilitates the conversion of instance variables in a Packet.
Finally, the NetworkIO object manages all connections and sends Packets over the network. The NetworkIO has a built-in server and can connect to any number of external servers, so you could reasonably manage all of a program’s network traffic through a single NetworkIO instance. Clients and external connections are kept track of with Maps that associate an IP address with data. Incoming Packets are stored in Queues, where the oldest Packets are first. All you have to do is put certain methods in the serverEvent(), clientEvent(), and disconnectEvent() methods to make things work.
While the library works (you can test it with the provided example), it has a couple of features that need improvement:

  1. Method names can be confusing, and there are a lot of methods. In the future, I may make a 2.0.0 version that refactors method names and design.
  2. There is no protection for DDOS attacks, the NetworkIO’s buffers may get stuck if filled with too much junk. I am thinking of a solution to this, but I have no background in cybersecurity. For now, be careful who you let connect to your device.

This is the first library I have created (ever), so its quality may leave some things to be desired. However, I hope that some of you may find this useful and incorporate it into your projects. Feel free to fork the project on Github, make suggestions, or report bugs.
Thanks!
-Shwaa

6 Likes