1. XenForo 1.5.14 中文版——支持中文搜索!现已发布!查看详情
  2. Xenforo 爱好者讨论群:215909318 XenForo专区

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

Discussion in '软件资讯' started by 漂亮的石头, 2018-01-16.

  1. 漂亮的石头

    漂亮的石头 版主 Staff Member

    Joined:
    2012-02-10
    Messages:
    488,114
    Likes Received:
    47
    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 方法的情况下有可能无法正确关闭的问题。
    Firefly 4.7.0 正式版发布,增加新的 WebSocket APIs下载地址
     
Loading...