FireNio構(gòu)建通訊項(xiàng)目的異步 io 框架
FireNio Project
FireNio 是基于 java nio 開發(fā)的一款可快速構(gòu)建網(wǎng)絡(luò)通訊項(xiàng)目的異步 IO 框架,其以簡(jiǎn)單易用的 API 和優(yōu)良的性能深受開發(fā)者喜愛。
項(xiàng)目特色
- 支持協(xié)議擴(kuò)展,已知的擴(kuò)展協(xié)議有:
- LengthValue協(xié)議,支持傳輸文本數(shù)據(jù)
- HTTP1.1協(xié)議(lite),示例: https://www.firenio.com/
- WebSocket協(xié)議,示例: https://www.firenio.com/web-socket/chat/index.html
- Protobase(自定義協(xié)議),支持傳輸文本或二進(jìn)制數(shù)據(jù)
- 輕松實(shí)現(xiàn)斷線重連(輕松實(shí)現(xiàn)心跳機(jī)制)
- 支持SSL(jdkssl,openssl)
- 壓力測(cè)試
快速入門
- 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 )
License
FireNio is released under the Apache License 2.0.
評(píng)論
圖片
表情
