Receive Stream of data from Socket Connection -- Android
<h2>What i want to achieve:</h2>

<p>Step 1 >> Open a socket connection :</p>

<pre><code>Socket socket = new Socket(IPADDRESS, PORTNUMBER);
</code></pre>

<p>Step 2 >> Start to send &amp; receive data from the Socket:</p>

<pre><code>PrintWriter pw = new PrintWriter(socket.getOutputStream(),true);
pw.write(dataForSocket + "\n");//Sending Data to socket....

BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
String translatedMessage = br.readLine();
Log.d(TAG, "Translated Message = "+translatedMessage);//Recieving data from Socket...
</code></pre>

<p>Step 3 >> Receive data from Socket &amp; keep on updating the UI...</p>

<h2>What did i tried till now:</h2>

<pre><code>public class AsyncThread extends AsyncTask&lt;String, String, String&gt; {

//High priority UI variables goes below....
private PrintStream out;
private Socket socket;
private BufferedReader in;


//Medium priority NON-UI variables goes below.....
public static final String SERVER_IP = "203.197.xx.xxx";
public static final int SERVER_PORT = 4xxx;


//Least priority variables goes below.....
private final String TAG = "AsyncThread";


@Override
protected String doInBackground(String... params) {

    try {
        socket = new Socket(SERVER_IP, SERVER_PORT);
        String dataForSocket = "A_LARGE_STRING_OF_DATA_SEPERATED_AND_END_WITH_\n";

        /////////////---------CODE TO READ &amp; WRITE------------\\\\\\\\\\\\\\\\\\\\\\\\\

//            out = new PrintStream(socket.getOutputStream(), true);
//            in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
//
//
//            out.write(dataForSocket.getBytes());
//            String message = in.readLine();
//            Log.d(TAG, "Message from Socket == "+message);



        PrintWriter pw = new PrintWriter(socket.getOutputStream(),true);
        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));

        // Send first message - Message is being correctly received
              pw.write(dataForSocket + "\n");
//            pw.write(dataForSocket);
        // Send off the data



        String translatedMessage = br.readLine();
        Log.d(TAG, "Translated Message = "+translatedMessage);//In every case this comes null....


//            pw.flush();
//            pw.close();


    }
    catch(Exception e){
        e.printStackTrace();
    }

    return null;
}//doInBackground
}//async task class closes here.....
</code></pre>

<p>But the BufferedReader is always null. So, i don't know what is wrong.</p>

<h1>Thus as a conclusion:</h1>

<p>If somebody could give me the exact steps &amp; guide me to get through this scenario then i will be very grateful to you.</p>

<p>P.S. : Till now i am not even able to connect to the Socket :-(
I tried running on device, running on Emulator, running on Genymotion nothing works.</p>

<p>Also, if somebody could provide me some kind of Online tester then please provide me the same.</p>