Giter Site home page Giter Site logo

newboy2004 / baseio Goto Github PK

View Code? Open in Web Editor NEW

This project forked from firenio/firenio

0.0 2.0 0.0 24.15 MB

An io framework project based on java nio

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

License: Apache License 2.0

Batchfile 0.13% Java 96.40% Shell 0.06% HTML 0.55% JavaScript 2.48% CSS 0.37%

baseio's Introduction

BaseIO Project

License License

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

项目特色

  • 轻松实现断线重连(轻松实现心跳机制)
  • 超过64W QPS的处理速度(Socket,I7-4790,Win10)
  • 超过40W QPS的处理速度(Http1.1,I7-4790,Win10)
  • 简易应用容器:
  • 支持简易热部署,示例: https://www.generallycloud.com/system-redeploy
  • 支持部署WEB,微服务等(依据协议而定)
  • 轻松实现简易负载均衡(可定制),已知策略:
  • 基于hash的虚拟节点策略
  • 轮询负载节点策略
  • 支持组件扩展,已知的扩展插件有:
  • 简易MQ,offer msg,poll msg
  • 简易实时UDP通讯,用作音/视频实时交互
  • 简易权限认证系统,用于限制单位时间内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
  • 私有协议(自己定义的协议报文头/协议报文体),支持传输文本和二进制数据及混合数据

快速入门

  • Maven引用:
  <dependency>
  	<groupId>com.generallycloud</groupId>
  	<artifactId>baseio-all</artifactId>
  	<version>3.1.8-SNAPSHOT</version>
  </dependency>  
  • 服务端:

      public static void main(String[] args) throws Exception {
    
      	IoEventHandleAdaptor eventHandleAdaptor = new IoEventHandleAdaptor() {
    
      		@Override
      		public void accept(SocketSession session, ReadFuture future) throws Exception {
      			future.write("yes server already accept your message:");
      			future.write(future.getReadText());
      			session.flush(future);
      		}
      	};
      	
      	SocketChannelContext context = new SocketChannelContextImpl(new ServerConfiguration(18300));
      	
      	SocketChannelAcceptor acceptor = new SocketChannelAcceptor(context);
      	
      	context.addSessionEventListener(new LoggerSocketSEListener());
      	
      	context.setIoEventHandleAdaptor(eventHandleAdaptor);
      	
      	context.setProtocolFactory(new FixedLengthProtocolFactory());
    
      	acceptor.bind();
      }
  • 客户端:

      public static void main(String[] args) throws Exception {
    
      	IoEventHandleAdaptor eventHandleAdaptor = new IoEventHandleAdaptor() {
    
      		@Override
      		public void accept(SocketSession session, ReadFuture future) throws Exception {
      			System.out.println();
      			System.out.println("____________________"+future.getReadText());
      			System.out.println();
      		}
      	};
      	
      	SocketChannelContext context = new SocketChannelContextImpl(new ServerConfiguration("localhost", 18300));
    
      	SocketChannelConnector connector = new SocketChannelConnector(context);
    
      	context.setIoEventHandleAdaptor(eventHandleAdaptor);
      	
      	context.addSessionEventListener(new LoggerSocketSEListener());
    
      	context.setProtocolFactory(new FixedLengthProtocolFactory());
      	
      	SocketSession session = connector.connect();
    
      	FixedLengthReadFuture future = new FixedLengthReadFutureImpl(context);
    
      	future.write("hello server!");
    
      	session.flush(future);
      	
      	ThreadUtil.sleep(100);
    
      	CloseUtil.close(connector);
      }

详见 {baseio-test}

演示及用例

License

BaseIO is released under the Apache License 2.0.

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.