I currently have a connection established to some middleware, through which I send SQL queries to a database.
I'm having some trouble with converting the DataInputStream to a useable format (Whether or not that is a String). I looked at another StackOverflow question, however this did not resolve my problem since using
in.readLine();
is 'deprecated', whatever that means. I need to be able to read the response from my middleware.
private class NetworkTask extends AsyncTask
{
protected Integer doInBackground(String... params)
{
Message message = networkHandler.obtainMessage();
String ip = "example ip";
int port = 1234;
try
{
InetAddress serverAddr = InetAddress.getByName(ip);
Log.d("EventBooker", "C: Connecting...");
Socket socket = new Socket(serverAddr, port);
DataInputStream in = new DataInputStream(socket.getInputStream());
try
{
Log.d("EventBooker", "C: Connected. Sending command.");
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())), true);
out.println(params[0]);
networkHandler.sendMessage(message);
Log.d("EventBooker", "C: Sent.");
}
catch (Exception e)
{
Log.e("EventBooker", "S: Error", e);
}
Log.d("EventBooker", "C: Reading...");
Log.d("EventBooker", "C: Response read, closing.");
socket.close();
Log.d("Eventbooker", "C: Closed.");
}
catch (Exception e)
{
Log.e("EventBooker", "C: Error", e);
}
return 1;
}
}