Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Network Application connected to Amazon EC2
    text
    copied!<p>I'm kind of new in this kind of development. To be short I'm working on a android app which sends a string to the cloud (I have a virtual server machine on Amazon), everything works well sending the string from my phone to the server machine, I print the string I'm sending and it works!. But when getting the response back from the server to my android app (I'm running it on my android phone) I don't get anything (The response should be a string + another string concatenated), that's it, easy right? But unfortunately I can't receive it back. I tested the server side and It's working properly (The amazon EC2). I'm not really sure if I can do what Im doing which is: </p> <p>CREATING ransmission code to send the String by using a SOCKET TO SEND DATA TO THE CLOUD ON THE doInBackground() method from the AsyncTask class. In the same method doInBackground I do the code to receive the response back by using a ServerSocket to receive the response back from the cloud. Is it possible or do I need another thread or something like that? </p> <p>Here is my code: </p> <pre><code>`import android.os.Bundle; import android.app.Activity; import android.widget.TextView; import java.io.DataInputStream; import java.io.DataOutputStream; import java.net.*; import android.os.AsyncTask; import android.view.View; public class ReadWebpageAsyncTask extends Activity { private TextView textView; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); textView = (TextView) findViewById(R.id.TextView01); } private class DownloadWebPageTask extends AsyncTask&lt;String, Void, String&gt; { @Override protected String doInBackground(String... urls) { String response = ""; //Transmission try { Socket socket = new Socket("MyAmazonServerIp", 5678); DataOutputStream salida = new DataOutputStream (socket.getOutputStream()); salida.writeUTF("Llego Perfectamente"); socket.close(); salida.close(); } catch (Exception e) { e.printStackTrace(); } //Final ends // Reception boolean ak=true; try { ServerSocket ServerSock = new ServerSocket(7896); while(ak) { Socket cl=ServerSock.accept(); InetAddress ipC = cl.getInetAddress(); DataInputStream en= new DataInputStream(cl.getInputStream()); response= en.readUTF(); //response= response.toString(); ak=false; } } catch(Exception exp) { exp.printStackTrace(); } // Reception ends return response; } //doInBackground ends @Override protected void onPostExecute(String result) { textView.setText(result); } } public void readWebpage(View view) { DownloadWebPageTask task = new DownloadWebPageTask(); task.execute(new String[] { "????" }); } }` </code></pre> <p>I will really appreciate any help since I've been working on this for days and I have not been able to solve it. Thanks,</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload