Giter Club home page Giter Club logo

protobuf-nio's Introduction

Build Status

protobuf-nio

Simple library to send and receive protobuf messages using Java NIO sockets

Pros
  • Pure Java NIO sockets (no netty / mina dependencies)
  • Protobuf-friendly API's
  • Good throughput
  • Scalable: Handles many connections from a single thread
Cons
  • 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

Getting Started

Server side

Create server and connect
// 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);

Client side

Create client and connect
// 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);

Benchmark

Throughput

With buffer size = 8 Kb

SampleClientBenchmarkTest - Sending and receiving 1000000 message took 2145 milliseconds
SampleClientBenchmarkTest - Throughput: 466.20 messages per millisecond (round-trip)

Handle multiple connections from a single thread

...
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..

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.