hunt-net 0.5.1

A network library for hunt.


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

Build Status

hunt-net

A net library for DLang, hunt library based. hunt-net have codec to encoding and decoding tcp streaming frames.

Using codec to build a TcpServer

import hunt.net;
import hunt.net.codec.textline;

import hunt.logging;

void main()
{
    NetServerOptions options = new NetServerOptions();
    NetServer server = NetUtil.createNetServer!(ThreadMode.Single)(options);

    server.setCodec(new TextLineCodec);
    server.setHandler(new class NetConnectionHandler
    {
        override void messageReceived(Connection connection, Object message)
        {
            import std.format;

            string str = format("data received: %s", message.toString());
            connection.write(str);
        }
    }).listen("0.0.0.0", 9999);
}

Using codec to build a TcpClient

import hunt.net;
import hunt.net.codec.textline;

import hunt.logging;

void main()
{
    NetClient client = NetUtil.createNetClient();

    client.setCodec(new TextLineCodec);
    client.setHandler(new class NetConnectionHandler
    {
        override void messageReceived(Connection connection, Object message)
        {
            import std.format;
            import hunt.String;

            string str = format("data received: %s", message.toString());
            
            connection.write(new String(str));
        }
    }).connect("localhost", 9999);
}
Dependencies:
hunt-extra
Versions:
0.5.1 2020-Jul-10
0.5.0 2020-May-21
0.4.13 2020-May-18
0.4.12 2020-May-12
0.4.11 2020-May-08
Show all 17 versions
Download Stats:
  • 1 downloads today

  • 26 downloads this week

  • 109 downloads this month

  • 2314 downloads total

Score:
2.3
Short URL:
hunt-net.dub.pm