Skip to content
forked from FireNio/firenio

🐳🐳An [easy of use, simple, not bad of performance] io framework project based on java nio

License

Notifications You must be signed in to change notification settings

yun14128/baseio

 
 

Repository files navigation

BaseIO Project

Website Maven central License

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

项目特色

快速入门

  • Maven引用:
  <dependency>
  	<groupId>com.generallycloud</groupId>
  	<artifactId>baseio-all</artifactId>
  	<version>3.2.4.Release</version>
  </dependency>  
  • Simple Server:
  public static void main(String[] args) throws Exception {
      IoEventHandleAdaptor eventHandleAdaptor = new IoEventHandleAdaptor() {
          @Override
          public void accept(SocketSession session, Future future) throws Exception {
              FixedLengthFuture f = (FixedLengthFuture) future;
              future.write("yes server already accept your message:", session.getEncoding());
              future.write(f.getReadText(), session.getEncoding());
              session.flush(future);
          }
      };
      NioEventLoopGroup group = new NioEventLoopGroup();
      ChannelContext context = new ChannelContext(new Configuration(8300));
      ChannelAcceptor acceptor = new ChannelAcceptor(context, group);
      context.addSessionEventListener(new LoggerSocketSEListener());
      context.setIoEventHandle(eventHandleAdaptor);
      context.setProtocolCodec(new FixedLengthCodec());
      acceptor.bind();
  }
  • Simple Client:
  public static void main(String[] args) throws Exception {
      IoEventHandleAdaptor eventHandleAdaptor = new IoEventHandleAdaptor() {
          @Override
          public void accept(SocketSession session, Future future) throws Exception {
              FixedLengthFuture f = (FixedLengthFuture) future;
              System.out.println();
              System.out.println("____________________" + f.getReadText());
              System.out.println();
          }
      };
      NioEventLoopGroup group = new NioEventLoopGroup();
      ChannelContext context = new ChannelContext(new Configuration(8300));
      ChannelConnector connector = new ChannelConnector(context, group);
      context.setIoEventHandle(eventHandleAdaptor);
      context.addSessionEventListener(new LoggerSocketSEListener());
      context.setProtocolCodec(new FixedLengthCodec());
      SocketSession session = connector.connect();
      FixedLengthFuture future = new FixedLengthFutureImpl();
      future.write("hello server!", session);
      session.flush(future);
      ThreadUtil.sleep(100);
      CloseUtil.close(connector);
  }

更多样例详见 {baseio-test}

演示及用例

License

BaseIO is released under the Apache License 2.0.

了解更多,加入该项目QQ群,更多java相关技术均可在此讨论

  • QQ群号码:540637859
  • 点击链接加入:img
  • 扫码加入:
    image

About

🐳🐳An [easy of use, simple, not bad of performance] io framework project based on java nio

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 85.5%
  • JavaScript 13.5%
  • Other 1.0%