Skip to content

Commit

Permalink
fix reconnect when remote closed
Browse files Browse the repository at this point in the history
  • Loading branch information
rikaaa0928 committed Oct 14, 2024
1 parent 48f1615 commit aa3994d
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions app/src/main/java/moe/rikaaa0928/uot/UogClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class UogClient(val lPort: Int, val endpoint: String, val password: String) {
GlobalScope.launch {
while (!stop.get()) {
try {
val innerStop = AtomicBoolean(false)
val id = random.nextInt(1000);
val url = URL(endpoint)
val engine =
Expand Down Expand Up @@ -77,7 +78,8 @@ class UogClient(val lPort: Int, val endpoint: String, val password: String) {
} catch (ignore: Exception) {

} finally {
Log.d("UogClient", "grpc read stop: " + id)
Log.d("UogClient", "grpc read stop: $id")
udpSocket!!.close()
}
}
val buffer = ByteArray(bufferSize)
Expand All @@ -101,11 +103,11 @@ class UogClient(val lPort: Int, val endpoint: String, val password: String) {
} catch (e: Exception) {
if (e !is SocketTimeoutException) {
Log.e("UpgClient", "grpc write", e)
java.util.concurrent.TimeUnit.MILLISECONDS.sleep(100L)
break
}
}
}
Log.d("UogClient", "grpc write stop: " + id)
Log.d("UogClient", "grpc write stop: $id")
} catch (e: Exception) {
Log.e("UogClient", "all", e)
}
Expand Down

0 comments on commit aa3994d

Please sign in to comment.