Skip to content

huntlabs/hunt-net

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 

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

About

High-performance network library for D programming language, event-driven asynchonous implemention(IOCP / kqueue / epoll).

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages