 
                                                                      1、smart-socket 简介
smart-socket,一款面向万物互联的 Java 通信框架。
产品特色:
-  易用:5分钟上手(前提:未曾遭受网上错误编解码知识的毒害) 
-  高性能:以算法之力充分驱动硬件算力之势,基于smart-socket的服务在通信性能方面可轻松超过其他计算机语言开发的程序,包括且不限于:C/C++、Golang、Rust、Erlang。 
推荐理由:
-  国产化,源码 100% 自研,信创首选产品。 
-  轻量化,生成 jar 包仅 62KB。 
-  插件化,多款实用插件辅助高效通信编程。 
-  人性化,低至分钟级的学习成本。 
舒适的编程体验;高效的运行表现;极少的资源开销。
smart-socket 在多方面都遥遥领先 netty,除了知名度。
2、 版本更新
-  拆解底层 write 线程模型。 
-  提升进程运行期间动态启停通信服务的资源管理可靠性。 
-  新增 IdleStatePlugin 插件 
-  内置线程调整为守护线程,实现优雅停机。 
-  新增示例代码 
这个版本主要带来了 IdleStatePlugin 插件,这是一款对通信链路闲置状态检测的插件。适用于弱网环境下,解决通信双方因无法感知链路异常,导致通信质量受损等问题。
按照 smart-socket 一贯的设计风格,此插件依旧开箱即用,用户可根据自身需求选择以下合适的集成模式。
 // 读、写通道闲置时长超过5秒,则断开连接 processor.addPlugin(new IdleStatePlugin<>(5000));  // 读通道闲置时长超过5秒,则断开连接 processor.addPlugin(new IdleStatePlugin<>(5000,true,false));  // 写通道闲置时长超过5秒,则断开连接 processor.addPlugin(new IdleStatePlugin<>(5000,false,true));  Maven
 <!-- JDK1.8 --> <dependencies>     <dependency>         <groupId>org.smartboot.socket</groupId>         <artifactId>aio-core</artifactId>         <version>1.5.36</version>     </dependency> </dependencies>    3、快速上手
3.1 引入Maven依赖
 <dependencies>     <dependency>         <groupId>org.smartboot.socket</groupId>         <artifactId>aio-core</artifactId>         <version>${version}</version>     </dependency> </dependencies>   3.2 定义协议
这里提供的示例是一种简单的字符串通信协议,仅作效果演示。实际场景中还需根据通信双方约定的协议实现编解码算法。
 import org.smartboot.socket.Protocol; import org.smartboot.socket.transport.AioSession;  import java.nio.ByteBuffer;  publicclass StringProtocol implements Protocol<String> {      @Override     public String decode(ByteBuffer readBuffer, AioSession session) {         int remaining = readBuffer.remaining();         if (remaining < Integer.BYTES) {             returnnull;         }         readBuffer.mark();         int length = readBuffer.getInt();         if (length > readBuffer.remaining()) {             readBuffer.reset();             returnnull;         }         byte[] b = newbyte[length];         readBuffer.get(b);         readBuffer.mark();         returnnew String(b);     } }   3.3 启动服务端
服务端通过System.out打印客户端传输过来的字符串内容,并将该内容原样传回至客户端。
 import org.smartboot.socket.MessageProcessor; import org.smartboot.socket.transport.AioQuickServer; import org.smartboot.socket.transport.WriteBuffer;  import java.io.IOException;  publicclass StringServer {      public static void main(String[] args) throws IOException {         MessageProcessor<String> processor = (session, msg) -> {             System.out.println("receive from client: " + msg);             WriteBuffer outputStream = session.writeBuffer();             try {                 byte[] bytes = msg.getBytes();                 outputStream.writeInt(bytes.length);                 outputStream.write(bytes);             } catch (IOException e) {                 e.printStackTrace();             }         };          AioQuickServer server = new AioQuickServer(8888, new StringProtocol(), processor);         server.start();     } }   try-catch中先后调用writeInt、write是一种协议编码手法,也是从事通信开发必须要理解和掌握的技能。
3.4 启动客户端
客户端与服务端建立TCP连接后,便向其发送hello smart-socket,当收到服务端的响应消息时,通过MessageProcessor的实现类进行控制台打印。
 import org.smartboot.socket.MessageProcessor; import org.smartboot.socket.transport.AioQuickClient; import org.smartboot.socket.transport.AioSession; import org.smartboot.socket.transport.WriteBuffer;  import java.io.IOException;  publicclass StringClient {      public static void main(String[] args) throws IOException {         MessageProcessor<String> processor = (session, msg) -> System.out.println("receive from server: " + msg);         AioQuickClient client = new AioQuickClient("localhost", 8888, new StringProtocol(), processor);         AioSession session = client.start();         WriteBuffer writeBuffer = session.writeBuffer();         byte[] data = "hello smart-socket".getBytes();         writeBuffer.writeInt(data.length);         writeBuffer.write(data);         writeBuffer.flush();     } }   4、我们的用户
篇幅有限,仅展示部分...
5、关于组织
smartboot开源组织,一个容易被误认为是在“重复造轮子”的低调组织。曾获得 2020 年度 OSC 中国开源项目「优秀 Gitee 组织 」荣誉。
该组织内的明星项目包括:
smart-socket
历时5年精炼出2千多行代码,轻松实现百万级长连接的 AIO 通信框架。
smart-http
基于 smart-socket 实现的 HTTP/1.1 web服务。
smart-servlet
基于 smart-http 实现的 Servlet 3.1 容器服务。
smart-mqtt
基于 smart-socket 实现的 MQTT 3.1.1/5.0 Broker&Client 服务。
smart-flow
一款具备可观测性的轻量级业务编排框架。组织地址:https://smartboot.tech/
代码仓库:https://gitee.com/smartboot
教程篇:
-  通信框架 smart-socket 设计概览 
-  五分钟上手 smart-socket 
-  smart-socket系列教程:工程结构 
-  smart-socket系列教程:通信协议 
插件篇:
-  smart-socket 插件化设计 
-  smart-socket 监控插件,性能分析的一柄利刃 
-  smart-socket 码流监控插件,让通信数据无所遁形 
杂篇
-  smart-socket 单机百万长连接背后的故事 
-  揭秘百万长连接背后的黑科技 
-  图解通信框架的调度模型 





 
		 
		 
		 
		

还没有评论,来说两句吧...