Ver Mensaje Individual
  #1 (permalink)  
Antiguo 03/10/2018, 16:29
polpolpol
 
Fecha de Ingreso: julio-2011
Ubicación: guadalajara mX
Mensajes: 84
Antigüedad: 12 años, 9 meses
Puntos: 6
Espera multicast

buen dia!!

Tengo un problema con un multicast! al momento de usar el receive() se queda congelada la app supongo que espera el mensaje siendo una funcion bloqueante, pero envio muchos paquetes algrupo y aun sigue congelada la app

codigo:
Código:
    void recivirDireccion() {
        p= null;
        try {
            InetAddress group = InetAddress.getByName("224.6.3.54");
            multicast = new MulticastSocket(port);
            multicast.joinGroup(group);
            Toast.makeText(this,"bind: "+port,Toast.LENGTH_SHORT).show();
            msj.setText("Esperando en puerto: "+port);
            /*
            String msg = "hello";
            DatagramPacket d = new DatagramPacket(msg.getBytes(),msg.length(),group,port);
            multicast.send(d);*/
            byte[] buf = new byte[512];
            DatagramPacket recv = new DatagramPacket(buf,buf.length);
            multicast.receive(recv);
            msj.setText(recv.getData().toString());
            multicast.close();
        } catch (SocketException e) {
            port++;
            e.printStackTrace();
            recivirDireccion();
        } catch (UnknownHostException e) {
            e.printStackTrace();
            multicast.close();
        } catch (IOException e) {
            e.printStackTrace();
            multicast.close();
        }
    }
y esta es la captura del paquete (wireshark) que supuestamente debe recivir mi app:

Internet Protocol Version 4, Src: 192.168.1.76, Dst: 224.6.3.54
0100 .... = Version: 4
.... 0101 = Header Length: 20 bytes (5)
Differentiated Services Field: 0x00 (DSCP: CS0, ECN: Not-ECT)
Total Length: 34
Identification: 0x069d (1693)
Flags: 0x0000
Time to live: 1
Protocol: UDP (17)
Header checksum: 0x0dfe [validation disabled]
[Header checksum status: Unverified]
Source: 192.168.1.76
Destination: 224.6.3.54
User Datagram Protocol, Src Port: 51380, Dst Port: 34445
Source Port: 51380
Destination Port: 34445
Length: 14
Checksum: 0xc208 [unverified]
[Checksum Status: Unverified]
[Stream index: 5550]
Data (6 bytes)
Data: 617175727272
[Length: 6]

notan algun problema en el codigo!?? (aparte de que no lo he implementado en un hilo ! )

Gracias por la atencion!! :D