• 授权协议:Apache
  • 开发厂商:-
  • 软件语言:Java
  • 更新日期:2019-05-15
FireNio

FireNio ProjectFireNio 是基于 java nio 开发的一款可快速构建网络通讯项目的异步 IO 框架,其以简单易用的 API 和优良的性能深受开发者喜爱。</dependency>Simple Server:public static void main throws Exception {

FireNio 构建通讯项目的异步 io 框架 项目简介

FireNio ProjectFireNio 是基于 java nio 开发的一款可快速构建网络通讯项目的异步 IO 框架,其以简单易用的 API 和优良的性能深受开发者喜爱。项目特色支持协议扩展,已知的扩展协议有: LengthValue协议,支持传输文本数据 HTTP1.1协议(lite),示例: https://www.firenio.com/ WebSocket协议,示例: https://www.firenio.com/web-socket/chat/index.html Protobase(自定义协议),支持传输文本或二进制数据 轻松实现断线重连(轻松实现心跳机制) 支持SSL(jdkssl,openssl) 压力测试 tfb benchmark 快速入门Maven引用:<dependency>
<groupId>com.firenio</groupId>
<artifactId>firenio-all</artifactId>
<version>1.2.1</version>
</dependency>Simple Server:public static void main(String[] args) throws Exception {

IoEventHandle eventHandleAdaptor = new IoEventHandle() {

@Override
public void accept(Channel ch, Frame f) throws Exception {
String text = f.getStringContent();
f.setContent(ch.allocate());
f.write("yes server already accept your message:", ch);
f.write(text, ch);
ch.writeAndFlush(f);
}
};
ChannelAcceptor context = new ChannelAcceptor(8300);
context.addChannelEventListener(new LoggerChannelOpenListener());
context.setIoEventHandle(eventHandleAdaptor);
context.addProtocolCodec(new LengthValueCodec());
context.bind();
}Simple Client:public static void main(String[] args) throws Exception {
ChannelConnector context = new ChannelConnector("127.0.0.1", 8300);
IoEventHandle eventHandle = new IoEventHandle() {
@Override
public void accept(Channel ch, Frame f) throws Exception {
System.out.println();
System.out.println("____________________" + f.getStringContent());
System.out.println();
context.close();
}
};

context.setIoEventHandle(eventHandle);
context.addChannelEventListener(new LoggerChannelOpenListener());
context.addProtocolCodec(new LengthValueCodec());
Channel ch = context.connect(3000);
LengthValueFrame frame = new LengthValueFrame();
frame.setString("hello server!");
ch.writeAndFlush(frame);
}更多样例详见 {firenio-test}演示及用例HTTP Demo:https://www.firenio.com/index.html WebSocket聊天室 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 )LicenseFireNio is released under the Apache License 2.0.

FireNio 构建通讯项目的异步 io 框架 评论内容