//阻塞知道成功建立连接
val timer = Timer()
val lastTime = System.currentTimeMillis()
val timerTask = object : TimerTask() {
override fun run() {
if (System.currentTimeMillis() - lastTime > 10000) {
context.runOnUiThread {
Toast.makeText(context, "连接超时", Toast.LENGTH_SHORT).show()
}
timer.cancel()
}
}
}
timer.schedule(timerTask,0, 10000)
11-02
9588
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)