Firefly 4.7.0 正式版发布,增加新的 WebSocket APIs

栏目: 软件资讯 · 发布时间: 7年前

内容简介:Firefly 4.7.0 增加了新的 WebSocket APIs,改进了 HTTP 2 编解码器的性能,并修复了一些 bug。 新的 WebSocket APIs 例如: public static void main(String[] args) {     SimpleWebSocketServer s...

Firefly 4.7.0 增加了新的 WebSocket APIs,改进了 HTTP 2 编解码器的性能,并修复了一些 bug。

新的 WebSocket APIs 例如:

public static void main(String[] args) {
    SimpleWebSocketServer server = $.createWebSocketServer();
    server.webSocket("/helloWebSocket")
          .onConnect(conn -> conn.sendText("OK."))
          .onText((text, conn) -> System.out.println("The server received: " + text))
          .listen("localhost", 8080);

    SimpleWebSocketClient client = $.createWebSocketClient();
    client.webSocket("ws://localhost:8080/helloWebSocket")
          .onText((text, conn) -> System.out.println("The client received: " + text))
          .connect()
          .thenAccept(conn -> conn.sendText("Hello server."));
}

也增加了 Kotlin DSL 版 APIs,例如:

fun main(args: Array<String>) {
    val scheduler = Schedulers.createScheduler()
    val p = Paths.get(HttpServer::class.java.getResource("/").toURI())

    HttpServer {
        router {
            httpMethod = HttpMethod.GET
            paths = listOf("/favicon.ico", "/static/*")
            handler(StaticFileHandler(p.toAbsolutePath().toString()))
        }

        router {
            httpMethod = HttpMethod.GET
            path = "/"
            asyncHandler { renderTemplate("template/websocket/index.mustache") }
        }

        webSocket("/helloWebSocket") {
            onConnect {
                val future = scheduler.scheduleAtFixedRate(
                        { it.sendText("Current time: " + Date()) },
                        0, 1, TimeUnit.SECONDS)
                it.onClose { future.cancel() }
            }

            onText { text, _ ->
                println("Server received: " + text)
            }
        }
    }.listen("localhost", 8080)
}

这个例子中 WebSocket 服务和 HTTP 服务公用一个端口。

更多详情请参考 WebSocket 文档

更新日志:

  1. 增加新的 WebSocket DSL APIs。

  2. 优化 HTTP 2 编解码性能。

  3. 修复了 HTTP1 Upgrade 机制时效的问题。

  4. 修复了 TCP Session 在并发调用 close 和 write 方法的情况下有可能无法正确关闭的问题。


【声明】文章转载自:开源中国社区 [http://www.oschina.net]


以上所述就是小编给大家介绍的《Firefly 4.7.0 正式版发布,增加新的 WebSocket APIs》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

腾讯网UED体验设计之旅

腾讯网UED体验设计之旅

任婕 等 / 电子工业出版社 / 2015-4 / 99.00元

《腾讯网UED体验设计之旅》是腾讯网UED的十年精华输出,涵盖了丰富的案例、极富冲击力的图片,以及来自腾讯网的一手经验,通过还原一系列真实案例的幕后设计故事,从用户研究、创意剖析、绘制方法、项目管理等实体案例出发,带领读者经历一场体验设计之旅。、 全书核心内容涉及网媒用户分析与研究方法、门户网站未来体验设计、H5技术在移动端打开的触控世界、手绘原创设计、改版迭代方法、文字及信息图形化设计、媒......一起来看看 《腾讯网UED体验设计之旅》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试