hunt-imf 0.0.6
A tcp-server framework.
To use this package, run the following command in your project's root directory:
Manual usage
Put the following dependency into your project's dependences section:
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 clientchatroom
two executable programs include chatclient and chatserver
build
hunt-imf
dub buildhelloworld
dub build -c=helloworldchatclient
dub build -c=chatclientchatserver
dub build -c=chatserver
Quick start
Proto
- define a
.proto
file namedhelloworld.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
andprotoc-gen-d
compileshelloworld.proto
tohellowrold.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();
- Registered by spring
- 0.0.6 released 5 years ago
- huntlabs/hunt-imf
- www.huntlabs.net
- Apache-2.0
- Copyright (c) 2017-2019, HuntLabs
- Dependencies:
- protobuf, hunt-net
- Versions:
-
0.2.0-beta.1 2019-Oct-15 0.1.0 2019-Mar-25 0.0.7 2019-Mar-12 0.0.6 2019-Mar-12 0.0.5 2019-Jan-25 - Download Stats:
-
-
0 downloads today
-
0 downloads this week
-
0 downloads this month
-
546 downloads total
-
- Score:
- 0.9
- Short URL:
- hunt-imf.dub.pm