Avoid NoSuchElementException if the connection stalls.

This commit is contained in:
akwizgran
2011-10-28 13:13:05 +01:00
parent 0728f76933
commit 40689b7e6e

View File

@@ -19,12 +19,16 @@ abstract class BluetoothTest {
out.println(CHALLENGE);
System.out.println("Sent challenge: " + CHALLENGE);
Scanner in = new Scanner(s.getInputStream());
String response = in.nextLine();
System.out.println("Received response: " + response);
if(BluetoothClientTest.RESPONSE.equals(response)) {
System.out.println("Correct response");
if(in.hasNextLine()) {
String response = in.nextLine();
System.out.println("Received response: " + response);
if(BluetoothClientTest.RESPONSE.equals(response)) {
System.out.println("Correct response");
} else {
System.out.println("Incorrect response");
}
} else {
System.out.println("Incorrect response");
System.out.println("No response");
}
s.dispose(true);
} catch(IOException e) {
@@ -36,14 +40,18 @@ abstract class BluetoothTest {
void receiveChallengeAndSendResponse(StreamTransportConnection s) {
try {
Scanner in = new Scanner(s.getInputStream());
String challenge = in.nextLine();
System.out.println("Received challenge: " + challenge);
if(BluetoothServerTest.CHALLENGE.equals(challenge)) {
PrintStream out = new PrintStream(s.getOutputStream());
out.println(RESPONSE);
System.out.println("Sent response: " + RESPONSE);
if(in.hasNextLine()) {
String challenge = in.nextLine();
System.out.println("Received challenge: " + challenge);
if(BluetoothServerTest.CHALLENGE.equals(challenge)) {
PrintStream out = new PrintStream(s.getOutputStream());
out.println(RESPONSE);
System.out.println("Sent response: " + RESPONSE);
} else {
System.out.println("Incorrect challenge");
}
} else {
System.out.println("Incorrect challenge");
System.out.println("No challenge");
}
s.dispose(true);
} catch(IOException e) {