Skip to content

Commit

Permalink
Should not crash app when StateSync fails to bind.
Browse files Browse the repository at this point in the history
  • Loading branch information
usertoroot committed Dec 6, 2024
1 parent 4066ce7 commit 7c9e9d5
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions app/src/main/java/com/futo/platformplayer/states/StateSync.kt
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,23 @@ class StateSync {
Logger.i(TAG, "Sync key pair initialized (public key = ${publicKey})")

_thread = Thread {
val serverSocket = ServerSocket(PORT)
_serverSocket = serverSocket
try {
val serverSocket = ServerSocket(PORT)
_serverSocket = serverSocket

Log.i(TAG, "Running on port ${PORT} (TCP)")
Log.i(TAG, "Running on port ${PORT} (TCP)")

while (_started) {
val socket = serverSocket.accept()
val session = createSocketSession(socket, true) { session, socketSession ->
while (_started) {
val socket = serverSocket.accept()
val session = createSocketSession(socket, true) { session, socketSession ->

}

session.startAsResponder()
}

session.startAsResponder()
} catch (e: Throwable) {
Logger.e(TAG, "Failed to bind server socket to port ${PORT}", e)
UIDialogs.toast("Failed to start sync, port in use")
}
}.apply { start() }

Expand Down

0 comments on commit 7c9e9d5

Please sign in to comment.