我听到了“蓝色素”电话的听觉。 这一read子将遭到另一只read子的杀害和重新启用。 当它收到杀人信号时,它关闭了蓝色ServerSocket,从而导致接受的IOException,并摆脱了无限的lo。 但有时,在这些开端和重新启用听众UsingRfcommWithserviceRecord(电话)时,将收集一个“坏账号”的IOException,并过早地撤出。 我认为,在杀人时,我可能不会正确地关闭BT部分,而只是说什么还没有。 难道有人会给我一些要点?
private class ReceiveThread extends Thread {
private final static String TAG = "ReceiveThread";
private BluetoothServerSocket mmBtServer;
private BluetoothSocket mmBtSocket;
public ReceiveThread() {
setName(TAG);
}
public void run() {
if(D) Log.d(TAG,"RceiveThread running");
while(true) {
try {
SetState(SERVICE_STATE.LISTENING);
mmBtServer = mBtAdapter.listenUsingRfcommWithServiceRecord(mAppName, mUUID);
if(D) Log.d(TAG,"ReceiveThd accepting connection");
mmBtSocket = mmBtServer.accept();
// Close server once socket establishes
mmBtServer.close();
if(D) Log.d(TAG, "Connection Established");
SetState(SERVICE_STATE.CONNECTED_BUSY);
/** Handle Processing **/
// Close socket
mmBtSocket.close();
} catch (IOException e) {
SetState(SERVICE_STATE.NOT_CONNECTED);
Log.d(TAG,"IOException in ReceiveThread", e);
break;
}
SetState(SERVICE_STATE.CONNECTED_IDLE);
}
}
public void kill() {
try {
if(mmBtSocket!=null) mmBtSocket.close();
if(mmBtServer!=null) mmBtServer.close();
} catch (IOException e) {
Log.d(TAG,"Failure killing ReceiveThread", e);
}
SetState(SERVICE_STATE.NOT_CONNECTED);
}
}