微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

BaseIO 项目特色 基于 Java NIO 的异步 IO 框架

程序名称:BaseIO 项目特色

授权协议: Apache

操作系统: 跨平台

开发语言: Java

BaseIO 项目特色 介绍

BaseIO是基于java nio开发的一款可快速构建网络通讯项目的异步IO框架,其以简单易用的API和优良的性能深受开发者喜爱。

项目特色

快速入门

  • Maven引用:


       com.generallycloud
       baseio-all
       3.2.6.RELEASE
      

  • Simple Server:

    public static void main(String[] args) throws Exception {
          IoEventHandle eventHandle = new IoEventHandle() {
              @Override
              public void accept(NioSocketChannel channel, Frame frame) throws Exception {
                  FixedLengthFrame f = (FixedLengthFrame) frame;
                  frame.write(“yes server already accept your message:”, channel.getCharset());
                  frame.write(f.getReadText(), channel.getCharset());
                  channel.flush(frame);
              }
          };
          ChannelContext context = new ChannelContext(8300);
          ChannelAcceptor acceptor = new ChannelAcceptor(context);
          context.addChannelEventListener(new LoggerChannelOpenListener());
          context.setIoEventHandle(eventHandle);
          context.setProtocolCodec(new FixedLengthCodec());
          acceptor.bind();
      }

  • Simple Client:

    public static void main(String[] args) throws Exception {
          IoEventHandle eventHandle = new IoEventHandle() {
              @Override
              public void accept(NioSocketChannel channel, Frame frame) throws Exception {
                  FixedLengthFrame f = (FixedLengthFrame) frame;
                  System.out.println();
                  System.out.println(“________” + f.getReadText());
                  System.out.println();
              }

    };
          ChannelContext context = new ChannelContext(8300);
          ChannelConnector connector = new ChannelConnector(context);
          context.setIoEventHandle(eventHandle);
          context.addChannelEventListener(new LoggerChannelOpenListener());
          context.setProtocolCodec(new FixedLengthCodec());
          NioSocketChannel channel = connector.connect();
          FixedLengthFrame frame = new FixedLengthFrame();
          frame.write(“hello server!”, channel);
          channel.flush(frame);
          ThreadUtil.sleep(100);
          CloseUtil.close(connector);
      }

更多样例详见 {baseio-test}

BaseIO 项目特色 官网

https://www.generallycloud.com/index.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐