Hello,
I have a problem with client code on Android.
I connect to the server without problems and send data to the buttons
created ...
I need to leave the connection open to transmit and receive data from
the server.
As I can create a loop to read server entries possible?
Example code: client for Android.
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class SdsycClientActivity extends Activity {
public BufferedReader input;
public Socket sss = null;
PrintWriter out = null;
String st;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
Socket sss = new Socket("192.168.1.102",1327);
out = new PrintWriter(sss.getOutputStream(), true);
input = new BufferedReader(new
InputStreamReader(sss.getInputStream()));
// ???????????????????????????????????
while (true) {
TextView text = (TextView)
findViewById(R.id.tvd_estado);
st = input.readLine();
text.setText(st);
}
//????????????????????????????????????
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch ( IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void desconecta(View view){
out.close();
finish();
}
public void boton1(View view){
out.println ("ANDROID:1");
}
public void boton2(View view){
out.println ("ANDROID:2");
}
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Thank you very much.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en