<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          BaseIO基于 Java NIO 的異步 IO 框架

          聯(lián)合創(chuàng)作 · 2023-09-29 12:18

          BaseIO是基于java nio開發(fā)的一款可快速構(gòu)建網(wǎng)絡(luò)通訊項(xiàng)目的異步IO框架,其以簡(jiǎn)單易用的API和優(yōu)良的性能深受開發(fā)者喜愛。

          項(xiàng)目特色

          • 支持協(xié)議擴(kuò)展,已知的擴(kuò)展協(xié)議有:

            • Redis協(xié)議(僅作測(cè)試),示例:詳見 {baseio-test}

            • LineBased協(xié)議(基于換行符的消息分割),示例:詳見 {baseio-test}

            • FixedLength協(xié)議(固定長(zhǎng)度報(bào)文頭),支持傳輸文本和二進(jìn)制數(shù)據(jù)

            • HTTP1.1協(xié)議(lite),示例: https://www.generallycloud.com/

            • WebSocket協(xié)議,示例: https://www.generallycloud.com/web-socket/chat/index.html

            • Protobase(自定義協(xié)議),支持傳輸文本和二進(jìn)制數(shù)據(jù)及混合數(shù)據(jù)

          • 輕松實(shí)現(xiàn)斷線重連(輕松實(shí)現(xiàn)心跳機(jī)制)

          • 支持SSL(jdkssl,openssl)

          • 壓力測(cè)試

            • 超過200W QPS的處理速度(Http1.1,I7-4790,16.04.1-Ubuntu)  wrk壓測(cè)

          快速入門

          • Maven引用:

            <dependency>
            	<groupId>com.generallycloud</groupId>
            	<artifactId>baseio-all</artifactId>
            	<version>3.2.6.RELEASE</version>
            </dependency>
          • Simple Server:

            public static void main(String[] args) throws Exception {
                IoEventHandle eventHandle = new IoEventHandle() {
                    @Override
                    public void accept(NioSocketChannel channel, Frame frame) throws Exception {
                        FixedLengthFrame f = (FixedLengthFrame) frame;
                        frame.write("yes server already accept your message:", channel.getCharset());
                        frame.write(f.getReadText(), channel.getCharset());
                        channel.flush(frame);
                    }
                };
                ChannelContext context = new ChannelContext(8300);
                ChannelAcceptor acceptor = new ChannelAcceptor(context);
                context.addChannelEventListener(new LoggerChannelOpenListener());
                context.setIoEventHandle(eventHandle);
                context.setProtocolCodec(new FixedLengthCodec());
                acceptor.bind();
            }
          • Simple Client:

            public static void main(String[] args) throws Exception {
                IoEventHandle eventHandle = new IoEventHandle() {
                    @Override
                    public void accept(NioSocketChannel channel, Frame frame) throws Exception {
                        FixedLengthFrame f = (FixedLengthFrame) frame;
                        System.out.println();
                        System.out.println("____________________" + f.getReadText());
                        System.out.println();
                    }
          
                };
                ChannelContext context = new ChannelContext(8300);
                ChannelConnector connector = new ChannelConnector(context);
                context.setIoEventHandle(eventHandle);
                context.addChannelEventListener(new LoggerChannelOpenListener());
                context.setProtocolCodec(new FixedLengthCodec());
                NioSocketChannel channel = connector.connect();
                FixedLengthFrame frame = new FixedLengthFrame();
                frame.write("hello server!", channel);
                channel.flush(frame);
                ThreadUtil.sleep(100);
                CloseUtil.close(connector);
            }

          更多樣例詳見 {baseio-test}

          瀏覽 20
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  色老板成人在线 | 黄片久久久久久久 | 毛片18| 免费在线观看视频无码 | 天天操天天日天天插 |