Hola buenas!
Tengo un problema al enviar paquetes TCP, no lo consigo, al ejecutarse esta parte del code se cierra la app.
Esto se ejecuta con un thread
- Código: Seleccionar todo
final Runnable ejecutarAccionudp =new Runnable (){
public void run(){
Socket socket = null;
DataOutputStream dataOutputStream = null;
DataInputStream dataInputStream = null;
try {
InetAddress sip = InetAddress.getByName(SERVERIP);
socket = new Socket(sip, SERVERPORT);
Toast.makeText(getApplication(), "1", Toast.LENGTH_SHORT).show();
dataOutputStream = new DataOutputStream(socket.getOutputStream());
Toast.makeText(getApplication(), "2", Toast.LENGTH_SHORT).show();
dataInputStream = new DataInputStream(socket.getInputStream());
Toast.makeText(getApplication(), "3", Toast.LENGTH_SHORT).show();
dataOutputStream.writeUTF("Hola1");
Toast.makeText(getApplication(), "4", Toast.LENGTH_SHORT).show();
String textInNow = dataInputStream.readUTF();
Toast.makeText(getApplication(), "5: " + textInNow, Toast.LENGTH_SHORT).show();
dataOutputStream.writeUTF("Hola2");
Toast.makeText(getApplication(), "6", Toast.LENGTH_SHORT).show();
textInNow = dataInputStream.readUTF();
Toast.makeText(getApplication(), "7: " + textInNow, Toast.LENGTH_SHORT).show();
} catch (UnknownHostException e) {
e.printStackTrace();
Toast.makeText(getApplication(), "Error1", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(getApplication(), "Error2", Toast.LENGTH_SHORT).show();
}
finally{
if (dataOutputStream != null){
try {
dataOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (dataInputStream != null){
try {
dataInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (socket != null){
try {
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
};
Gracias