hunt-imf 0.1.0

A tcp-server framework.


To use this package, run the following command in your project's root directory:

hunt-imf

Introduction

hunt-imf is a tcp-based instant messaging framework and can be used for Push service, Chat service, Game service, etc.

  • serializes messages using protobuf
  • uses binary protocol (type & length)
  • implements message distribution, message routing, and network IO
  • ensure that all messages in the same context are serialized

Depends

Tools

  • protoc apt-get install protoc-compile
  • protoc-gen-d plugin generates D code for proto3 .proto files only

examples

  • helloworld An executable program containing the server and the client
  • chatroom two executable programs include chatclient and chatserver

build

  • hunt-imf dub build
  • helloworld dub build -c=helloworld
  • chatclient dub build -c=chatclient
  • chatserver dub build -c=chatserver

Quick start

Proto

  • define a .proto file named helloworld.proto:
syntax = "proto3";
package helloworld;

// The request message containing the user's name.
message HelloRequest {
 string name = 1;
}

// The response message containing the greetings
message HelloReply {
 string message = 1;
}
  • using protoc and protoc-gen-d compiles helloworld.proto to hellowrold.d:
./protoc --plugin="protoc-gen-d" --d_out=~/example/  -I~/example/hellowrold ~/hellworld.proto

COMMAND

define a dlang source file named command.d:

 enum COMMAND
 {
    HELO_REQ = 1001,
    HELO_RES = 1002,
 }

Controller

  • define a server side control class:
class ServerController
{
    mixin MakeRouter;

    @route(COMMAND.HELO_REQ)
    void hello(HelloRequest request)
    {
        auto reply = new HelloReply();
        reply.message = "hello " ~ request.name;
        sendMessage(context , Command.HELO_RES , reply);

    }
}
  • define a client size control class:
class ClientController
{
    mixin MakeRouter;

    @route(Command.HELO_RES)
    void hello(HelloReply reply)
    {
        writeln(reply.message);
    }
}

Bootstrap

   auto app = new Application();

   auto server = app.createServer("127.0.0.1" , 3003);
   auto client = app.createClient("127.0.0.1" , 3003);
   client.setOpenHandler((Context context){
       auto hello = new HelloRequest();
       hello.name = "world";
       context.sendMessage(Command.Q_HELO , hello);
   });
   app.run();
Dependencies:
protobuf, hunt-net
Versions:
0.1.0 2019-Mar-25
0.0.7 2019-Mar-12
0.0.6 2019-Mar-12
0.0.5 2019-Jan-25
0.0.4 2019-Jan-24
Show all 9 versions
Download Stats:
  • 0 downloads today

  • 2 downloads this week

  • 6 downloads this month

  • 478 downloads total

Score:
0.5
Short URL:
hunt-imf.dub.pm