Several times before, especially while developing applications for Android, I have found myself (re)implementing TCP clients and servers in different programming languages, most notably Java for Android clients and Python serverside. Everytime a new message or parameter had to be implemented, this would mean writing (or at least copying) a lot of boilerplate code... twice - once for each language.
In order to make things a easier for me, and honor the DRY (Don't Repeat Yourself) principle, I came up with the idea for a way to define network communication between clients and a server regardless of the programming language(s) in which the client and server would be implemented.
Therefore I am proud to annouce the Network Protocol Specification Language (or NPSL), currently in version 0.1. This early version is capable of outputting both a client and a server in Python (of course, more languages will come later - I am currently working on Java), who are perfectly able to communicate through the defined network protocol.
I intend to release the code into public domain, but I have yet to find an appropriate license for it.
If you are curious to take a look, the code is publicly available on GitHub: https://github.com/jesperborgstrup/NPSL
An example NPSL-file looks like this:
mediaplayer 100 ( => 10 set_volume (Volume, byte) => 20 get_volume <= 20 get_volume (Volume, byte) => 150 get_playlist <= 150 get_playlist (Tracks, strings) )
The resulting protocol is defined primarily through messages, which follow the format:
<direction> <id>, <name>, [<parameters>].
The direction is either
<=, meaning "from client to server" and "from server to client", respectively and defines which way the message goes. (There is also a
<> direction, meaning both ways). The id is the internal value that actually gets sent through the connection, name is, well, a name for the message, and finally a message has a (possibly empty) list of parameters, where a parameter consists of a name and a data type.
Seven data types are possible as of this version: Byte, integer, list of integers, float, string, list of strings and arbitrary binary data.
Messages can be arranged into modules (which can also contain other modules) as the mediaplayer in the example, which allows for easy distinction of messages in the message handling code.