hunt-net 0.4.7

A network library for hunt.


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:

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);
}

TODO

  • [ ] Improve support for SSL
  • [ ] Improve APIs
Dependencies:
hunt
Versions:
0.7.1 2022-Feb-18
0.7.0 2021-Oct-28
0.6.6 2021-Apr-11
0.6.5 2021-Mar-31
0.6.4 2021-Mar-10
Show all 26 versions
Download Stats:
  • 4 downloads today

  • 35 downloads this week

  • 101 downloads this month

  • 6039 downloads total

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