Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.

02. Developer Guids

Naveen Balasooriya edited this page Jul 2, 2024 · 2 revisions

My recommendation is to read this after you go through the User guides for Socket Data Handler.

Data types

Socket Data Handler is using 3 data types for communications.

  • NONE (just a String request of the header) [type 0]
  • FILE (java.io.File) [type 1]
  • OBJECT (any serializable object) [type 2]

The DataHandler

You must need an instance of DataHandler to send and receive data using this library. It's only bound to this library, and it's not a must for the protocol. For more info. please look at the Java-Doc.

The header

Socket Data Handler uses a unique protocol for communications. If you are going to contribute or make your own library for this, you should know how it works.

The main part of this protocol is the header. In the library, the DataProcessor is the core for making that header (the serialize method). All headers are UTF-8 Strings.

Sample header

{6,0,0}

header only contains 3 elements enclosed by {} and separated by ,.

  • The first element is the bytes length of the request (UTF-8 String).
  • The second element is the data-type
  • The third element is the bytes length of the body

Let's assume we want to send a File of 2KB with the request, /sampleFile. Then the header is like this.

{11,1,2048}

Now the library knows the bounds of the variables!

The timestamp

All invocation of the send method is making a header (please look at The header section for more about the headers). The timestamp is part of the requested content, but does not show up in the header. Timestamp is using the Java system milliseconds. If you're going to use ping requests, please take a look at that. But why it's not in the header? It's because the timestamp always has 13 bytes. It can be hardcoded!

Appending the content

  • Append the header
  • Append the request
  • Append the timestamp
  • If it's a File, append the file extension and $ (eg: myImage.png -> png$)
  • If there's a body, append it

Central Repository Minimum JDK version

Clone this wiki locally