Hi,
i have really hard time to recive and just output the messages that comes from the server that I'm connected to. I've serched for hours but couldn't finde anything on internet.
The code works fine connecting, but cannot output the data
I know that I should read the stream from the socket with streamreader, but then I'm stuck.
Here is my code that is written by help from tutorials.
Thanks
===================================
private TextView serverStatus;
private boolean connected = false;
private boolean recive = false;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
serverStatus = (TextView) findViewById(R.id.textView1);
serverStatus.setText("Hello World!");
try{
InetAddress serverAddr = InetAddress.getByName("192.168.1.1");
Socket CLSocket = new Socket(serverAddr, 2000);
connected = true;
while(connected)
{
try{
serverStatus.setText("CONNECTED");
BufferedReader in = new BufferedReader(new InputStreamReader(CLSocket.getInputStream()));
String line = null;
while ((line = in.readLine()) != null)
{
serverStatus.setText(line);
}
}
catch(Exception e)
{
Log.e("ClientActivity", "S: Error", e);
}
}
CLSocket.close();
Log.d("ClientActivity", "C: Closed.");
}
catch (Exception e) {
serverStatus.setText("CONNECTECTION ERROR");
Log.e("ClientActivity", "C: Error", e);
connected = false;
}
==================================
i have really hard time to recive and just output the messages that comes from the server that I'm connected to. I've serched for hours but couldn't finde anything on internet.
The code works fine connecting, but cannot output the data

I know that I should read the stream from the socket with streamreader, but then I'm stuck.
Here is my code that is written by help from tutorials.
Thanks
===================================
public
class HelloActivity extends Activity {
private TextView serverStatus;
private boolean connected = false;
private boolean recive = false;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
serverStatus = (TextView) findViewById(R.id.textView1);
serverStatus.setText("Hello World!");
try{
InetAddress serverAddr = InetAddress.getByName("192.168.1.1");
Socket CLSocket = new Socket(serverAddr, 2000);
connected = true;
while(connected)
{
try{
serverStatus.setText("CONNECTED");
BufferedReader in = new BufferedReader(new InputStreamReader(CLSocket.getInputStream()));
String line = null;
while ((line = in.readLine()) != null)
{
serverStatus.setText(line);
}
}
catch(Exception e)
{
Log.e("ClientActivity", "S: Error", e);
}
}
CLSocket.close();
Log.d("ClientActivity", "C: Closed.");
}
catch (Exception e) {
serverStatus.setText("CONNECTECTION ERROR");
Log.e("ClientActivity", "C: Error", e);
connected = false;
}
==================================