Support for responding to multiple requests on the same connection

This commit is contained in:
Samuel Carlsson 2014-03-17 21:57:57 +01:00
parent 548acc6aa2
commit a872b5413e

View File

@ -16,35 +16,49 @@ public class AdbResponder implements Runnable {
@Override @Override
public void run() public void run()
{ {
System.out.println("Serving client");
try { try {
System.out.println("Serving client");
DataInput input = new DataInputStream(socket.getInputStream()); while (true)
OutputStreamWriter output = new OutputStreamWriter(socket.getOutputStream()); {
byte[] buffer = new byte[4]; DataInput input = new DataInputStream(socket.getInputStream());
input.readFully(buffer); OutputStreamWriter output = new OutputStreamWriter(socket.getOutputStream());
String encodedLength = new String(buffer, Charset.forName("utf-8")); byte[] buffer = new byte[4];
int length = Integer.parseInt(encodedLength, 16); input.readFully(buffer);
String encodedLength = new String(buffer, Charset.forName("utf-8"));
buffer = new byte[length]; System.out.println("DEBUG: " + encodedLength);
input.readFully(buffer); int length = Integer.parseInt(encodedLength, 16);
String command = new String(buffer, Charset.forName("utf-8"));
System.out.println("Command: " + command); buffer = new byte[length];
input.readFully(buffer);
if ("host:version".equals(command)) { String command = new String(buffer, Charset.forName("utf-8"));
output.write("OKAY"); System.out.println("Command: " + command);
send(output, "001F");
} if ("host:version".equals(command)) {
else if ("host:devices".equals(command)) { output.write("OKAY");
output.write("OKAY"); send(output, "001F"); // version. required to be 31
send(output, "X\tdevice\nY\tdevice"); System.out.println("OK");
} }
else else if ("host:transport-any".equals(command))
{ {
output.write("FAIL"); output.write("OKAY");
} System.out.println("OK");
output.flush(); }
else if ("host:devices".equals(command)) {
output.write("OKAY");
send(output, "X\tdevice\nY\tdevice");
System.out.println("OK");
}
else
{
output.write("FAIL");
send(output, "Unknown command: " + command);
System.out.println("FAIL");
}
output.flush();
}
} catch (IOException e) { } catch (IOException e) {
System.out.println(e.getMessage()); System.out.println(e.getMessage());
} }