zhuwenquan / baseio

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

Home Page:https://www.generallycloud.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BaseIO Project

Website Maven central License

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

Features

  • easy to support reconnect (easy to support heart beat)
  • simple application container
  • easy to supprot load balance, known:
    • virtual node based on hash
    • loop balance node
  • support protocol extend, known:
  • load test

Quick Start

  • Maven Dependency
  <dependency>
  	<groupId>com.generallycloud</groupId>
  	<artifactId>baseio-all</artifactId>
  	<version>3.2.2.RELEASE</version>
  </dependency>  
  • A simple server:
  public static void main(String[] args) throws Exception {
      IoEventHandleAdaptor eventHandleAdaptor = new IoEventHandleAdaptor() {
          @Override
          public void accept(SocketSession session, Future future) throws Exception {
              future.write("yes server already accept your message:");
              future.write(future.getReadText());
              session.flush(future);
          }
      };
      SocketChannelContext context = new NioSocketChannelContext(new ServerConfiguration(18300));
      //use java aio
      //		SocketChannelContext context = new AioSocketChannelContext(new ServerConfiguration(18300));
      SocketChannelAcceptor acceptor = new SocketChannelAcceptor(context);
      context.addSessionEventListener(new LoggerSocketSEListener());
      context.setIoEventHandleAdaptor(eventHandleAdaptor);
      context.setProtocolFactory(new FixedLengthProtocolFactory());
      acceptor.bind();
  }
  • A simple client:
  public static void main(String[] args) throws Exception {
      IoEventHandleAdaptor eventHandleAdaptor = new IoEventHandleAdaptor() {
          @Override
          public void accept(SocketSession session, Future future) throws Exception {
              System.out.println();
              System.out.println("____________________" + future.getReadText());
              System.out.println();
          }
      };
      SocketChannelContext context = new NioSocketChannelContext(new ServerConfiguration("localhost", 18300));
      //use java aio
      //		SocketChannelContext context = new AioSocketChannelContext(new ServerConfiguration(18300));
      SocketChannelConnector connector = new SocketChannelConnector(context);
      context.setIoEventHandleAdaptor(eventHandleAdaptor);
      context.addSessionEventListener(new LoggerSocketSEListener());
      context.setProtocolFactory(new FixedLengthProtocolFactory());
      SocketSession session = connector.connect();
      FixedLengthFuture future = new FixedLengthFutureImpl(context);
      future.write("hello server!");
      session.flush(future);
      ThreadUtil.sleep(100);
      CloseUtil.close(connector);
  }

more samples {baseio-test}

Sample at website:

License

BaseIO is released under the Apache License 2.0.

To learn more, join this QQ group, more java technique can talk at there.

  • QQ group NO: 540637859
  • Join by click this link: img
  • Scan QR code:
    image

About

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

https://www.generallycloud.com/

License:Apache License 2.0


Languages

Language:Java 87.0%Language:JavaScript 12.1%Language:HTML 0.5%Language:CSS 0.3%Language:Batchfile 0.1%Language:Shell 0.0%