現在、Bluetooth を介して 2 つのデバイス間でデータを含む多数の個別の文字列を送信していますが、何らかの理由で同様の文字列を送信するのに不規則な時間がかかります。以下は、2 つの類似した文字列の書き込み時間の例です。
String: K:92:281:-50529028
Write time: 2
String: K:93:281:-50529028
Write time: 41
測定時間はミリ秒単位です。これが私の書き込み関数です。データを送信するために BufferedOutputStream を使用しています。
public synchronized void write(byte[] bytes) {
long writeTime = System.currentTimeMillis();
try {
mmOutStream.write(bytes,0,bytes.length);
mmOutStream.write('\n');
mmOutStream.flush();
}catch(IOException e) {
Log.e(TAG,"Write IOException");
cancel();}
String s = new String(bytes);
Log.d(TAG,"String: " + s);
Log.d(TAG,"Write time: " + (System.currentTimeMillis() - writeTime));
}
大幅に速度が低下しているのは、1 つの大きな均一な書き込みではなく、個別の書き込みを実行しているためである可能性はありますか?