EVERY package contains a header and a JSON payload. The header was composed by 4 variables: version, type, length and reserve. The header.Length = len(Header itself) + len(JSON payload).
4 bytes | 4 bytes | 4 bytes | 4 bytes | |
version | type | length | reserve | JSON payload |
For example:
{"jsonkv":"1.0","operate":"put","key":"tomato","value":"999","id":"1"}
The length of JSON itself is 65, and the Header's size is an constant which always be 16. In this case, the bytes stream of this package looks like this:
Version | Type | Length | Reserve | JSON payload |
0 | 0 | 81 | 0 | {"jsonkv":"1.0","operate":"put","key":"1","value":"999","id":"1"} |
<-- {"jsonkv": version, "operate": operations, "key": key, "value": value, "id": operation id}
version | 1.0 |
operate | put / get / delete |
key | string value |
value | string value |
id | operation id -- generated by client |
Example: {"jsonkv":"1.0","operate":"put","key":"1","value":"999","id":"1"}
--> {"jsonkv": version, "result": {"value": value, "code": code, "message": message}, "id": operation id}
version | 1.0 |
result | |
result - value | only 'get' operation will return value otherwise value = 0 or empty |
result - code | success : code == 0 errors: code > 0 |
result - message | success : message is empty errors: server will explain |
id | operation id -- generated by client |
Example: {"jsonkv": "1.0", "result": {"value": "0", "code": "1000", "message": "key does not exist.“, "id": ”1“}[
{"jsonkv":"1.0","operate":"put","key":"1","value":"999","id":"1"},
{"jsonkv":"1.0","operate":"get","key":"2“,"value":"","id":"2"}
] [{"jsonkv": "1.0", "result": {"value":"0", "code":"0", "message": "put operation success"}, "id": "1"},
{"jsonkv": "1.0", "result": {"value":"999", "code":"0", "message": "get operation success"}, "id": "2"}
]<-- {"jsonagent": version, "operate": operations, "address": server address, "port": TCP server port}
Register | |
version | 1.0 |
operate | register |
address | server address( internet ip or domain name ) |
tcpport | TCP server port |
rpcport | RPC server port |
Unregister | |
version | 1.0 |
operate | unregister |
GetServerList | |
version | 1.0 |
operate | getserverlist |
protocol | tcp or rpc |
Example:
{"jsonagent":"1.0","operate":"register","address":"uw.umx.io","tcpport":"15001","rpcport":"15003"}
{"jsonagent":"1.0","operate":"unregister"}
{"jsonagent":"1.0","operate":"getserverlist","protocol":"tcp"}
--> {"jsonagent": version, "result": {"value": [{"address":"uw.umx.io","port",15003},], "code": code, "message": message}}
version | 1.0 |
result | |
result - value | json array contains server list if request is register, value=global server id |
result - code | success : code == 0 errors: code > 0 |
result - message | success : message is empty errors: server will explain |
Example:
{"jsonagent":"1.0","result":{"value":"2","code":"0","message":"register success"}}
{"jsonagent":"1.0","result":{"code":"0","message":"unregister success"}}
{"jsonagent":"1.0","result":{"value":[{"address":"uw.umx.io","port":15003}], "code":"0","message":"get tcp/rpc server list success"}}
Server will check every UDP package, if the package is larger or less than expected, the package will be dropped.
Client should check every response package. If the received package does not match the original length or there is no response under appropriate timeout, client have the responsibility to resend this request.