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

@ -17,34 +17,48 @@ 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());
OutputStreamWriter output = new OutputStreamWriter(socket.getOutputStream());
byte[] buffer = new byte[4];
input.readFully(buffer);
String encodedLength = new String(buffer, Charset.forName("utf-8"));
int length = Integer.parseInt(encodedLength, 16);
buffer = new byte[length]; while (true)
input.readFully(buffer); {
String command = new String(buffer, Charset.forName("utf-8")); DataInput input = new DataInputStream(socket.getInputStream());
System.out.println("Command: " + command); OutputStreamWriter output = new OutputStreamWriter(socket.getOutputStream());
byte[] buffer = new byte[4];
input.readFully(buffer);
String encodedLength = new String(buffer, Charset.forName("utf-8"));
System.out.println("DEBUG: " + encodedLength);
int length = Integer.parseInt(encodedLength, 16);
if ("host:version".equals(command)) { buffer = new byte[length];
output.write("OKAY"); input.readFully(buffer);
send(output, "001F"); String command = new String(buffer, Charset.forName("utf-8"));
} System.out.println("Command: " + command);
else if ("host:devices".equals(command)) {
output.write("OKAY");
send(output, "X\tdevice\nY\tdevice");
}
else
{
output.write("FAIL");
}
output.flush();
if ("host:version".equals(command)) {
output.write("OKAY");
send(output, "001F"); // version. required to be 31
System.out.println("OK");
}
else if ("host:transport-any".equals(command))
{
output.write("OKAY");
System.out.println("OK");
}
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());
} }