- This library proposes communicate method by JSON (RFC8259).
- This library provides automatically parsing JSON <-> POJO(Plain Old Java Object).
- This library requires (com.shimizukenta.jsonhub) for parsing.
- Use
0x00
byte as delimiter. append delimiter after JSON bytes.
- Open server sample
JsonCommunicator<Pojo> server = JsonCommunicators.openServer(
new InetSocketAddress("127.0.0.1", 10000),
Pojo.class);
- Open client sample
JsonCommunicator<Pojo> client = JsonCommunicators.openClient(
new InetSocketAddress("127.0.0.1", 10000),
Pojo.class);
If you set classOfT
, you can receive parsed POJO by #addPojoReceivedListener
- Send JSON
String json = "{\"name\": \"John\"}";
client.send(json);
- Send POJO
Pojo pojo = new Pojo();
pojo.name = "John";
client.send(pojo);
- Add listener for receive JSON
client.addJsonReceiveListener((String json) -> {
/* something ... */
});
- Add listener for receive parsed POJO
client.addPojoReceiveListener((Pojo pojo) -> {
/* something ... */
});
see also Examples.