Simple library to send and receive protobuf messages using Java NIO sockets
- Pure Java NIO sockets (no netty / mina dependencies)
- Protobuf-friendly API's
- Good throughput
- Scalable: Handles many connections from a single thread
- No support for SSL/TLS yet
Note: due to the way SSL Engine is implemented, adding SSL/TLS support will require major change to the code, this is also complained in here and here
// Create server listening to port 3456
ProtoServerocketChannel server = ProtoChannelFactory.newServer(3456).build();
// Register message handlers
server.addMessageReceivedHandler(this::onMessageReceived);
// Start the server
server.start();
// Sending message
// This call will not block.
server.sendMessage(protobufMessage);
// Create client to connect to localhost:3456
ProtoSocketChannel client = ProtoChannelFactory.newClient("localhost", 3456).build();
// Register message handlers
client.addMessageReceivedHandler(this::onMessageReceived);
// Connect
client.connect();
// Sending message
// This call will not block
client.sendMessage(protobufMessage);
With buffer size = 8 Kb
SampleClientBenchmarkTest - Sending and receiving 1000000 message took 2145 milliseconds
SampleClientBenchmarkTest - Throughput: 466.20 messages per millisecond (round-trip)
...
MultiClientsTest - Client 14996 is connected
MultiClientsTest - Client 14997 is connected
MultiClientsTest - Client 14998 is connected
MultiClientsTest - Client 14999 is connected
MultiClientsTest - All 15000 clients are connected
MultiClientsTest - All HeartBeat response messages have been received. Closing all clients..