This is my first open-source contribution for the development community. After spend some time in each project, creating a simple way to send a entire message/receive it, i’ve decided create a re-usable lib to simplify my work and from others.
When we start to learn socket communication in any language, the simple hello word where you can send/receive any data with any size in a single chunk, it looks like the ideal scenario, but when you deploy your app or system to communicate over the internet, some stranger things will start to happen.
After spend some time with research you gonna find some information about protocol, binary data, little endian, big endian, buffers, and so on. So your simple Hello World cannot greet the world, but only your Local Connection.
Many people prefer switch the socket communication to REST communication, because the high level API abstract the HTTP protocol for you, but if you need check connectivity, bi-directional communication or other features where HTTP does not provide maybe is adopt a protocol 😉
The EasySocket is a simple lib to solve the HelloWorld communication problem over the internet. It consists in two steps:
just add 4 bytes (an integer) at the beginning of the buffer to inform the total size of the message, and a method to
Read the first 4 bytes and accumulate in a buffer all incoming bytes until it complete the message size to emit a callback with the complete message.
A the present the following languages have the implementation of protocol:
- NodeJS – https://github.com/irineu/node-easysocket