-
Notifications
You must be signed in to change notification settings - Fork 0
02. Developer Guids
My recommendation is to read this after you go through the User guides for Socket Data Handler.
Socket Data Handler is using 3 data types for communications.
- NONE (just a
Stringrequest of theheader) [type0] - FILE (
java.io.File) [type1] - OBJECT (any
serializableobject) [type2]
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.
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!
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!
- Append the
header - Append the
request - Append the
timestamp - If it's a
File, append thefile extensionand$(eg: myImage.png ->png$) - If there's a body, append it