Skip to content

Commit 60df370

Browse files
committed
synchronized
1 parent bce1598 commit 60df370

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/main/kotlin/net/lz1998/mirai/entity/WebSocketBotClient.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,21 @@ class WebsocketBotClient(override var botId: Long, override var password: String
7676
override fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?) {
7777
println("websocket失败${t.message}")
7878
wsClient = null
79-
t.printStackTrace()
79+
// t.printStackTrace()
8080
wsConnect()
8181
super.onFailure(webSocket, t, response)
8282
}
8383
}
8484

8585

86-
@Synchronized
86+
// @Synchronized
8787
fun wsConnect() {
8888
if (wsClient == null) {
8989
println("ws try connect")
90-
wsClient = httpClient.newWebSocket(wsRequest, wsListener)
90+
synchronized(this) {
91+
wsClient = httpClient.newWebSocket(wsRequest, wsListener)
92+
}
93+
} else {
9194
return
9295
}
9396
sleep(5000)

0 commit comments

Comments
 (0)