您现在的位置是:首页 > 文章详情

smart-http 1.0.13 发布,支持 WebSocket 的 Http 服务器

日期:2020-04-02点击:424

smart-http 是一款采用 Java 语言编写的 Http 服务器,有别于业界知名的 Web容器:Tomcat、Undertow,smart-http 并不支持 Servlet 规范,但对于 Http 服务器所需的各项能力,它都具备。

smart-http 天生就是异步非阻塞的 I/O 模型,因为其通信内核采用了 smart-socket。所以无论是性能还是稳定性,都是非常出色的。 在 4核 2.9GHz 的电脑下服务启动耗时毫秒级,压测的 QPS 可达 73W,流量传输效率每秒突破百兆。

更新内容

  1. 采用面向对象思想重构 Http协议解码,增强代码可读性、可扩展性、可维护性。
  2. 支持WebSocket协议。
  3. 引入自定义日志框架,彻底解除jar包的三方依赖。
  4. 升级 smart-socket 至 1.4.9。

快速体验

  1. 在您的Maven工程中引入smart-http依赖。
     <dependency> <groupId>org.smartboot.http</groupId> <artifactId>smart-http-server</artifactId> <version>1.0.13</version> </dependency>

     

  2. 拷贝以下代码并启动。
     public class SimpleSmartHttp { public static void main(String[] args) { HttpBootstrap bootstrap = new HttpBootstrap(); //http消息 bootstrap.pipeline().next(new HttpHandle() { public void doHandle(HttpRequest request, HttpResponse response) throws IOException { response.write("hello world".getBytes()); } }); //websocket消息 bootstrap.wsPipeline().next(new WebSocketHandle() { public void doHandle(WebSocketRequest request, WebSocketResponse response) throws IOException { response.sendTextMessage("hello world"); } }); bootstrap.setPort(8080).start(); } }

     

  3. 浏览器访问:http://localhost:8080/ 或采用ws客户端请求ws://127.0.0.1:8080

更多文档请访问:https://smartboot.gitee.io/book/smart-http/

原文链接:https://www.oschina.net/news/114574/smart-http-1-0-13-released
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章