Bluetooth Chat Пример Android Server

Thread {
            bluetoothAdapter?.startDiscovery()
            val server : BluetoothServerSocket? = bluetoothAdapter?.listenUsingRfcommWithServiceRecord("Bluetooth", uuid)
            var loop = true
            while (loop) {
                Log.d("Server", "Printing")
                val bluetoothSocket: BluetoothSocket? = try {
                    server?.accept()
                } catch (e: IOException) {
                    Log.e("ServerSocket", "Socket's accept() failed", e)
                    e.printStackTrace()
                    null
                }
                bluetoothSocket?.let {
                    binder.socketConnectedCallback?.onSocketConnected(it)
                }
                server?.close()
                loop = false
            }
        }.start()
Real Raven