Code Monkey home page Code Monkey logo

baseio's Introduction

BaseIO Project

Website Maven central License

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

项目特色

  • 支持协议扩展,已知的扩展协议有:
    • Redis协议,示例:详见 {baseio-test}
    • Protobuf协议,示例:详见 {baseio-test}
    • LineBased协议(基于换行符的消息分割),示例:详见 {baseio-test}
    • FixedLength协议(固定长度报文头),支持传输文本和二进制数据
    • HTTP1.1协议(客户端,服务端),示例: https://www.generallycloud.com/
    • WebSocket协议(客户端,服务端),示例: https://www.generallycloud.com/web-socket/chat/index.html
    • Protobase(自定义协议),支持传输文本和二进制数据及混合数据
  • 轻松实现断线重连(轻松实现心跳机制)
  • 简易应用容器:
  • 压力测试
    • 超过200W QPS的处理速度(Http1.1,I7-4790,16.04.1-Ubuntu)  wrk压测

快速入门

  • 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

baseio's People

Contributors

wangkaish avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.