BluetoothChatの例に基づいて、AndroidBluetoothゲームを開発しています。うまく機能しているようですが、アプリを接続しようとすると5〜10回試行するたびにクラッシュします。一部のバッファがオーバーフローしているようです。1つのデバイスをサーバーとして使用し、別のデバイスをクライアントとして使用しています。クライアント(HTC EVO 4G)が次のトレースでクラッシュします:
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
そして最悪のことは、電話を再起動するまで、接続を再開できないことです。
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?
どんな助けでも役に立ちます!!