From 0cc94bf9983b5cd05681bc31c5bc72525dc08207 Mon Sep 17 00:00:00 2001 From: tursom Date: Sun, 4 Jul 2021 17:25:55 +0800 Subject: [PATCH] update WebSocketClient.kt --- .../src/main/kotlin/cn/tursom/core/ws/WebSocketClient.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ts-core/ts-ws-client/src/main/kotlin/cn/tursom/core/ws/WebSocketClient.kt b/ts-core/ts-ws-client/src/main/kotlin/cn/tursom/core/ws/WebSocketClient.kt index ac568d3..d96b825 100644 --- a/ts-core/ts-ws-client/src/main/kotlin/cn/tursom/core/ws/WebSocketClient.kt +++ b/ts-core/ts-ws-client/src/main/kotlin/cn/tursom/core/ws/WebSocketClient.kt @@ -1,5 +1,6 @@ package cn.tursom.core.ws +import cn.tursom.core.ShutdownHook import cn.tursom.core.buffer.ByteBuffer import cn.tursom.core.buffer.impl.NettyByteBuffer import io.netty.bootstrap.Bootstrap @@ -37,6 +38,12 @@ open class WebSocketClient( var ch: Channel? = null internal set + init { + ShutdownHook.addHook { + close() + } + } + fun open() { close() val scheme = if (uri.scheme == null) "ws" else uri.scheme