FireNio是基于javanio开发的一款可快速构建网络通讯项目的异步IO框架,其以简单易用的API和优良的性能深受开发者喜爱。
项目特色支持协议扩展,已知的扩展协议有:LengthValue协议,支持传输文本数据HTTP1.1协议(lite),示例: https://www.firenio.com/WebSocket协议,示例: https://www.firenio.com/web-socket/chat/index.htmlProtobase(自定义协议),支持传输文本或二进制数据轻松实现断线重连(轻松实现心跳机制)支持SSL(jdkssl,openssl)压力测试tfbbenchmark快速入门Maven引用:<dependency><groupId>com.firenio</groupId><artifactId>firenio-all</artifactId><version>1.2.1</version></dependency>SimpleServer:publicstaticvoidmain(String[]args)throwsException{IoEventHandleeventHandleAdaptor=newIoEventHandle(){@Overridepublicvoidaccept(Channelch,Framef)throwsException{Stringtext=f.getStringContent();f.setContent(ch.allocate());f.write("yesserveralreadyacceptyourmessage:",ch);f.write(text,ch);ch.writeAndFlush(f);}};ChannelAcceptorcontext=newChannelAcceptor(8300);context.addChannelEventListener(newLoggerChannelOpenListener());context.setIoEventHandle(eventHandleAdaptor);context.addProtocolCodec(newLengthValueCodec());context.bind();}SimpleClient:publicstaticvoidmain(String[]args)throwsException{ChannelConnectorcontext=newChannelConnector("127.0.0.1",8300);IoEventHandleeventHandle=newIoEventHandle(){@Overridepublicvoidaccept(Channelch,Framef)throwsException{System.out.println();System.out.println("____________________"+f.getStringContent());System.out.println();context.close();}};context.setIoEventHandle(eventHandle);context.addChannelEventListener(newLoggerChannelOpenListener());context.addProtocolCodec(newLengthValueCodec());Channelch=context.connect(3000);LengthValueFrameframe=newLengthValueFrame();frame.setString("helloserver!");ch.writeAndFlush(frame);}更多样例详见{firenio-test}演示及用例HTTPDemo:https://www.firenio.com/index.htmlWebSocket聊天室Demo:https://www.firenio.com/web-socket/chat/index.html(后端基于firenio,前端基于:https://github.com/socketio/socket.io/ )WebSocket小蝌蚪Demo:https://www.firenio.com/web-socket/rumpetroll/index.html(后端基于firenio,前端基于:https://github.com/danielmahal/Rumpetroll )LicenseFireNioisreleasedunderthe ApacheLicense2.0.
评论