Hello,
is anybody looks where could be probleme on code as follows. If is IP
address and PORT server on net allright, connection works well, but ..
try .. } catch "UnknownHostException" and "IOException " no works
(example IP not availbale on net..and so on).. appliaction freeze and
show errors for long time : "Activity ... is not responding".
code:
...
...
public class ClientTCP extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.communication);
final TextView textin = (TextView)findViewById(R.id.textback);
final TextView textin1 =
(TextView)findViewById(R.id.textback1);
final TextView textin2 =
(TextView)findViewById(R.id.textback2);
Button bsend = (Button)findViewById(R.id.bsendat);
bsend.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// TODO Auto-generated method stub
Socket s = null;
BufferedReader reader;
PrintWriter writer;
try {
s = new Socket("10.0.0.1", 14000);
InputStreamReader(s.getInputStream()));
textin1.setText("Spojení navázáno, odesílám
data ...");
writer = new PrintWriter(new
OutputStreamWriter(s.getOutputStream()));
writer.println("Hello Server");
writer.flush();
writer.close();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
textin1.setText("Error1");
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
textin1.setText("Error2");
e.printStackTrace();
} finally {
if (s != null){
try {
s.close();
textin2.setText("Socket terminated");
} catch (IOException e) {
// TODO Auto-generated catch
block
textin1.setText("Error3");
e.printStackTrace();
}}
}
}
});
}
}
--
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