86 Star 201 Fork 1

FireNio / firenio

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README-en.md 3.67 KB
一键复制 编辑 原始数据 按行查看 历史
wangkaish 提交于 2021-10-12 10:27 . 1

FireNio Project

Website Maven central License

FireNio is an io framework which can build network project fast, it based on java nio, it is popular with Developers because of simple and easy of use APIs and high-performance.

Features

Quick Start

  • Maven Dependency
  <dependency>
  	<groupId>com.firenio</groupId>
  	<artifactId>firenio-all</artifactId>
  	<version>1.3.6</version>
  </dependency>  
  • Simple Server:

  public static void main(String[] args) throws Exception {

      IoEventHandle eventHandleAdaptor = new IoEventHandle() {

          @Override
          public void accept(Channel ch, Frame f) throws Exception {
              String text = f.getStringContent();
              f.setContent(ch.allocateWithSkipHeader(1));
              f.write("yes server already accept your message:", ch);
              f.write(text, ch);
              ch.writeAndFlush(f);
          }
      };
      ChannelAcceptor context = new ChannelAcceptor(8300);
      context.addChannelEventListener(new LoggerChannelOpenListener());
      context.setIoEventHandle(eventHandleAdaptor);
      context.addProtocolCodec(new LengthValueCodec());
      context.bind();
  }
  • Simple Client:
  
  public static void main(String[] args) throws Exception {
      ChannelConnector context = new ChannelConnector("127.0.0.1", 8300);
      IoEventHandle eventHandle = new IoEventHandle() {
          @Override
          public void accept(Channel ch, Frame f) throws Exception {
              System.out.println();
              System.out.println("____________________" + f.getStringContent());
              System.out.println();
              context.close();
          }
      };

      context.setIoEventHandle(eventHandle);
      context.addChannelEventListener(new LoggerChannelOpenListener());
      context.addProtocolCodec(new LengthValueCodec());
      Channel          ch    = context.connect(3000);
      LengthValueFrame frame = new LengthValueFrame();
      frame.setString("hello server!", ch);
      ch.writeAndFlush(frame);
  }

more samples see project {firenio-test}

Sample at website:

License

FireNio is released under the Apache License 2.0.

Java
1
https://gitee.com/FireNio/firenio.git
git@gitee.com:FireNio/firenio.git
FireNio
firenio
firenio
master

搜索帮助