项目作者: huntlabs

项目描述 :
High-performance network library for D programming language, event-driven asynchonous implemention(IOCP / kqueue / epoll).
高级语言: D
项目地址: git://github.com/huntlabs/hunt-net.git
创建时间: 2018-06-15T09:41:49Z
项目社区:https://github.com/huntlabs/hunt-net

开源协议:Apache License 2.0

下载


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

  1. import hunt.net;
  2. import hunt.net.codec.textline;
  3. import hunt.logging;
  4. void main()
  5. {
  6. NetServerOptions options = new NetServerOptions();
  7. NetServer server = NetUtil.createNetServer!(ThreadMode.Single)(options);
  8. server.setCodec(new TextLineCodec);
  9. server.setHandler(new class AbstractNetConnectionHandler
  10. {
  11. override void messageReceived(Connection connection, Object message)
  12. {
  13. import std.format;
  14. string str = format("data received: %s", message.toString());
  15. connection.write(str);
  16. }
  17. }).listen("0.0.0.0", 9999);
  18. }

Using codec to build a TcpClient

  1. import hunt.net;
  2. import hunt.net.codec.textline;
  3. import hunt.logging;
  4. void main()
  5. {
  6. NetClient client = NetUtil.createNetClient();
  7. client.setCodec(new TextLineCodec);
  8. client.setHandler(new class AbstractNetConnectionHandler
  9. {
  10. override void messageReceived(Connection connection, Object message)
  11. {
  12. import std.format;
  13. import hunt.String;
  14. string str = format("data received: %s", message.toString());
  15. connection.write(new String(str));
  16. }
  17. }).connect("localhost", 9999);
  18. }