2013-02-04 104 views
0

我正在開發基於BluetoothChat示例的android藍牙遊戲。 它似乎工作得很好,但每5 - 10嘗試連接應用程序崩潰。看來,一些緩衝區溢出。我使用一個設備作爲服務器,另一個作爲客戶端。客戶端(HTC EVO 4G)與此跟蹤崩潰:藍牙聊天android連接/發現bug

02-04 21:11:54.139: DEBUG/BluetoothService(2048): start 
02-04 21:11:54.139: DEBUG/BluetoothService(2048): setState() 0 -> 1 
02-04 21:11:54.169: DEBUG/BluetoothService(130): new handle 9 
02-04 21:11:54.179: DEBUG/BluetoothService(2048): Socket Type: InsecureBEGIN mAcceptThreadThread[Thread-47,5,main] 
02-04 21:11:55.870: ERROR/BluetoothService.cpp(130): stopDiscoveryNative: D-Bus error in StopDiscovery: org.bluez.Error.Failed (Invalid discovery session) 
02-04 21:11:55.890: DEBUG/BluetoothService(2048): connect to: 10:BF:48:E8:C1:26 
02-04 21:11:55.890: DEBUG/BluetoothService(2048): setState() 1 -> 2 
02-04 21:11:55.900: INFO/BluetoothService(2048): BEGIN mConnectThread SocketType:Insecure 
02-04 21:11:55.900: ERROR/BluetoothService.cpp(130): stopDiscoveryNative: D-Bus error in StopDiscovery: org.bluez.Error.Failed (Invalid discovery session) 
02-04 21:11:57.222: DEBUG/BluetoothService(130): updateDeviceServiceChannelCache(10:BF:48:E8:C1:26) 
02-04 21:11:57.222: DEBUG/BluetoothService(130): uuid(system): 00001105-0000-1000-8000-00805f9b34fb -1 
02-04 21:11:57.232: DEBUG/BluetoothService(130): uuid(application): fa87c0d0-afac-11de-8a39-0800200c9a66 3 
02-04 21:11:57.232: DEBUG/BluetoothService(130): Making callback for fa87c0d0-afac-11de-8a39-0800200c9a66 with result 3 
02-04 21:12:05.910: ERROR/BluetoothService.cpp(130): stopDiscoveryNative: D-Bus error in StopDiscovery: org.bluez.Error.Failed (Invalid discovery session) 
02-04 21:12:06.491: DEBUG/BluetoothService(2048): stop 
02-04 21:12:35.779: DEBUG/BluetoothService(130): Tracked app 2048 died 
02-04 21:12:35.779: DEBUG/BluetoothService(130): Removing service record 8 for pid 2048 
02-04 21:12:35.789: DEBUG/BluetoothService(130): Tracked app 2048 died 
02-04 21:12:35.789: DEBUG/BluetoothService(130): Removing service record 2 for pid 2048 
02-04 21:12:35.789: DEBUG/BluetoothService(130): Tracked app 2048 died 
02-04 21:12:35.789: DEBUG/BluetoothService(130): Removing service record 1 for pid 2048 
02-04 21:12:35.799: DEBUG/BluetoothService(130): Tracked app 2048 died 
02-04 21:12:35.799: DEBUG/BluetoothService(130): Tracked app 2048 died 
02-04 21:12:35.799: DEBUG/BluetoothService(130): Tracked app 2048 died 
02-04 21:12:35.799: DEBUG/BluetoothService(130): Removing service record 7 for pid 2048 
02-04 21:12:35.809: DEBUG/BluetoothService(130): Tracked app 2048 died 
02-04 21:12:35.809: DEBUG/BluetoothService(130): Removing service record 4 for pid 2048 
02-04 21:12:35.819: DEBUG/BluetoothService(130): Tracked app 2048 died 
02-04 21:12:35.819: DEBUG/BluetoothService(130): Removing service record 6 for pid 2048 
02-04 21:12:35.819: DEBUG/BluetoothService(130): Tracked app 2048 died 
02-04 21:12:35.819: DEBUG/BluetoothService(130): Tracked app 2048 died 
02-04 21:12:35.819: DEBUG/BluetoothService(130): Removing service record 5 for pid 2048 
02-04 21:12:35.829: DEBUG/BluetoothService(130): Tracked app 2048 died 
02-04 21:12:35.829: DEBUG/BluetoothService(130): Tracked app 2048 died 
02-04 21:12:35.829: DEBUG/BluetoothService(130): Removing service record 3 for pid 2048 
02-04 21:12:35.829: DEBUG/BluetoothService(130): Tracked app 2048 died 
02-04 21:12:35.829: DEBUG/BluetoothService(130): Removing service record 9 for pid 2048 
02-04 21:12:35.839: DEBUG/BluetoothService(130): Tracked app 2048 died 
02-04 21:12:35.839: DEBUG/BluetoothService(130): Tracked app 2048 died 
02-04 21:12:35.839: DEBUG/BluetoothService(130): Tracked app 2048 died 
02-04 21:12:35.839: DEBUG/BluetoothService(130): Tracked app 2048 died 

而最糟糕的事情,我不能重新開始連接 - 直到我重新啓動我的phone.It拋出:

02-04 21:15:11.381: DEBUG/BluetoothService(2322): start 
02-04 21:15:11.381: DEBUG/BluetoothService(2322): setState() 0 -> 1 
02-04 21:15:12.432: ERROR/BluetoothService(2322): Socket Type: Insecurelisten() failed 
     java.io.IOException: Bad file number 
     at android.bluetooth.BluetoothSocket.throwErrnoNative(Native Method) 
     at android.bluetooth.BluetoothAdapter.createNewRfcommSocketAndRecord(BluetoothAdapter.java:884) 
     at android.bluetooth.BluetoothAdapter.listenUsingRfcommWithServiceRecord(BluetoothAdapter.java:820) 
     at com.insomniacpro.pillows.Bluetooth.BluetoothService$AcceptThread.<init>(BluetoothService.java:312) 
     at com.insomniacpro.pillows.Bluetooth.BluetoothService.start(BluetoothService.java:132) 
     at com.insomniacpro.pillows.engine.MultiGameActivity.onResume(MultiGameActivity.java:159) 
     at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1242) 
     at android.app.Activity.performResume(Activity.java:3904) 

有時服務器設備( Nexus 7)崩潰 - 我必須重新啓動才能開始工作。 堆棧:

java.io.IOException: Error: -1 
    at android.bluetooth.BluetoothAdapter.createNewRfcommSocketAndRecord(BluetoothAdapter.java:1035) 
    at android.bluetooth.BluetoothAdapter.listenUsingRfcommWithServiceRecord(BluetoothAdapter.java:951) 
    at com.insomniacpro.pillows.Bluetooth.BluetoothService$AcceptThread.<init>(BluetoothService.java:312) 
    at com.insomniacpro.pillows.Bluetooth.BluetoothService.start(BluetoothService.java:132) 
    at com.insomniacpro.pillows.engine.MultiGameActivity.onResume(MultiGameActivity.java:159) 
    at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1185) 

Maybe BluetoothChat app doesnt closes sockets well, when connection is closed? 

任何幫助將是有益的!

回答

0

最後我結束了這樣糟糕的解決方案:每次連接丟失或失敗時調用onFinish()。這適合我的情況,但不適用於其他情況。在我看來,BluetoothChat中的connectionLost()函數是不完整的。它應該以另一種方式清除端口。

+1

即使我面對這種情況。你在onFinish()上做什麼?你能分享一下嗎? – Basher51