mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 21:29:54 +01:00
Avoid NoSuchElementException if the connection stalls.
This commit is contained in:
@@ -19,12 +19,16 @@ abstract class BluetoothTest {
|
|||||||
out.println(CHALLENGE);
|
out.println(CHALLENGE);
|
||||||
System.out.println("Sent challenge: " + CHALLENGE);
|
System.out.println("Sent challenge: " + CHALLENGE);
|
||||||
Scanner in = new Scanner(s.getInputStream());
|
Scanner in = new Scanner(s.getInputStream());
|
||||||
String response = in.nextLine();
|
if(in.hasNextLine()) {
|
||||||
System.out.println("Received response: " + response);
|
String response = in.nextLine();
|
||||||
if(BluetoothClientTest.RESPONSE.equals(response)) {
|
System.out.println("Received response: " + response);
|
||||||
System.out.println("Correct response");
|
if(BluetoothClientTest.RESPONSE.equals(response)) {
|
||||||
|
System.out.println("Correct response");
|
||||||
|
} else {
|
||||||
|
System.out.println("Incorrect response");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Incorrect response");
|
System.out.println("No response");
|
||||||
}
|
}
|
||||||
s.dispose(true);
|
s.dispose(true);
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
@@ -36,14 +40,18 @@ abstract class BluetoothTest {
|
|||||||
void receiveChallengeAndSendResponse(StreamTransportConnection s) {
|
void receiveChallengeAndSendResponse(StreamTransportConnection s) {
|
||||||
try {
|
try {
|
||||||
Scanner in = new Scanner(s.getInputStream());
|
Scanner in = new Scanner(s.getInputStream());
|
||||||
String challenge = in.nextLine();
|
if(in.hasNextLine()) {
|
||||||
System.out.println("Received challenge: " + challenge);
|
String challenge = in.nextLine();
|
||||||
if(BluetoothServerTest.CHALLENGE.equals(challenge)) {
|
System.out.println("Received challenge: " + challenge);
|
||||||
PrintStream out = new PrintStream(s.getOutputStream());
|
if(BluetoothServerTest.CHALLENGE.equals(challenge)) {
|
||||||
out.println(RESPONSE);
|
PrintStream out = new PrintStream(s.getOutputStream());
|
||||||
System.out.println("Sent response: " + RESPONSE);
|
out.println(RESPONSE);
|
||||||
|
System.out.println("Sent response: " + RESPONSE);
|
||||||
|
} else {
|
||||||
|
System.out.println("Incorrect challenge");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Incorrect challenge");
|
System.out.println("No challenge");
|
||||||
}
|
}
|
||||||
s.dispose(true);
|
s.dispose(true);
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user