msgtrans 0.1.4

Message Transport Framework. Based on TCP, WebSocket, UDP transmission protocol.


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:

MsgTrans for DLang

Message Transport Framework. Based on TCP, WebSocket, UDP transmission protocol.

Create a Message Transport Server using msgtrans

import msgtrans;

import hunt.logging;

void main()
{
    MessageTransportServer server = new MessageTransportServer("test");

    server.addChannel(new TcpServerChannel(9001));
    server.addChannel(new WebSocketServerChannel(9002, "/ws"));

    server.acceptor((TransportContext ctx) {
        infof("New connection: id=%d", ctx.id());
    });

    server.start();
}

@TransportServer("test")
@TransportClient("test")
class MyExecutor : AbstractExecutor!(MyExecutor)
{

    @MessageId(MESSAGE.HELLO)
    void hello(TransportContext ctx, MessageBuffer buffer)
    {

        string name = cast(string) buffer.data;

        string welcomeText = "Hello " ~ name;

        ctx.send(new MessageBuffer(MESSAGE.WELCOME, cast(ubyte[]) welcomeText));
    }
}

Create a Client connect to Server

import msgtrans;

import hunt.logging;

void main()
{
    MessageTransportClient client = new MessageTransportClient("test");

    client.channel(new TcpClientChannel("127.0.0.1", 9001)).connect();

    string name = "zoujiaqing";

    auto buffer = new MessageBuffer(MESSAGE.HELLO, name.dup);

    client.send(buffer);

    getchar();
    client.close();
}

@TransportClient("test")
class MyExecutor : AbstractExecutor!(MyExecutor)
{
    @MessageId(MESSAGE.WELCOME)
    void welcome(TransportContext ctx, MessageBuffer buffer)
    {
        auto message = unserialize!WelcomeMessage(buffer.data);

        infof("message: %s", message.welcome);
    }
}
Dependencies:
hunt-openssl, protobuf, hunt-http, hunt-reflection
Versions:
0.1.4 2023-Apr-27
0.1.3 2021-Apr-20
0.1.2 2021-Apr-15
0.1.1 2021-Mar-18
0.0.11 2020-Dec-10
Show all 16 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 200 downloads total

Score:
0.4
Short URL:
msgtrans.dub.pm