Adding get host version method.

This commit is contained in:
Samuel Carlsson 2013-07-25 21:13:20 +02:00
parent 9eb33de413
commit b36ede6770
2 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,40 @@
package se.vidstige.jadb;
import java.io.DataInput;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.net.UnknownHostException;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
public class JadbConnection {
private Socket _socket;
private static final int DEFAULTPORT = 5037;
public JadbConnection() throws UnknownHostException, IOException
{
_socket = new Socket("localhost", DEFAULTPORT);
}
public void getHostVersion() throws IOException {
OutputStreamWriter writer = new OutputStreamWriter(_socket.getOutputStream());
DataInput reader = new DataInputStream(_socket.getInputStream());
writer.write("000Chost:version");
writer.flush();
byte[] response = new byte[4];
reader.readFully(response);
System.out.println(new String(response, Charset.forName("utf-8")));
}
public void close() throws IOException
{
_socket.close();
}
}

View File

@ -0,0 +1,14 @@
package se.vidstige.jadb.test;
import org.junit.Test;
import se.vidstige.jadb.JadbConnection;
public class JadbTestCases {
@Test
public void test() throws Exception {
JadbConnection jadb = new JadbConnection();
jadb.getHostVersion();
}
}