안드로이드 개발 질문/답변
(글 수 45,052)
아래 소스에서 send 시에 버퍼에 있는 정보를 바로 읽어와서 미쳐 다 읽어오지 못하는 현상이 발생하고 있습니다.
여기에서 sleep time 을 써서 읽어오는 시간을 강제로 늘려서 주려고 하는데요..
어떤 식으로 적용을 해야하는지 감이 안옵니다.
아래와 같이 해보긴했는데...결과값이 그대로이네요;
public void run() {
Log.i(TAG, "BEGIN mConnectedThread");
byte[] buffer = new byte[1024];
byte[] data = new byte[1024];
int bytes=0;
int bytes1=0;
int j=0;
// Keep listening to the InputStream while connected
while (true) {
try {
// Read from the InputStream
bytes = mmInStream.read(buffer);
bytes1 += bytes;
for (int i = 0; i < bytes; i++) {
data[j++] = buffer[i];
}
if((char)data[(j-1)] == '>'){
j=0;
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
mHandler.obtainMessage(BluetoothChat.MESSAGE_READ, bytes1, -1, data).sendToTarget();
bytes1=0;
}
} catch (IOException e) {
Log.e(TAG, "disconnected", e);
connectionLost();
break;
}
}
}
Log.i(TAG, "BEGIN mConnectedThread");
byte[] buffer = new byte[1024];
byte[] data = new byte[1024];
int bytes=0;
int bytes1=0;
int j=0;
// Keep listening to the InputStream while connected
while (true) {
try {
// Read from the InputStream
bytes = mmInStream.read(buffer);
bytes1 += bytes;
for (int i = 0; i < bytes; i++) {
data[j++] = buffer[i];
}
if((char)data[(j-1)] == '>'){
j=0;
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
mHandler.obtainMessage(BluetoothChat.MESSAGE_READ, bytes1, -1, data).sendToTarget();
bytes1=0;
}
} catch (IOException e) {
Log.e(TAG, "disconnected", e);
connectionLost();
break;
}
}
}



