Packet loss while receiving UDP broadcast in android device

后端 未结 5 1596
旧时难觅i
旧时难觅i 2021-01-05 03:46

For receiving UDP broadcast packets from the server to an android device, i used a service class and listen for packets in a thread. It receives the packet successfully. The

5条回答
  •  清酒与你
    2021-01-05 03:56

    I think your problem is mainly that you use Udp Broadcast over wifi.

    Their are two very well documented answers why this is a very slow way to operate and why there are much more packet losts:

    • answer number one.

    • answer number two.

    The thing I did to solve the extremely slow bandwidth was some kind of multi-unicast protocol:

    1. Manage the list of clients you have connected.
    2. Send each packet you have in your server to all of your clients separately with send call.

    This is the code in java:

      DatagramPacket packet = new DatagramPacket(buffer, size);
      packet.setPort(PORT);
    
      for (byte[] clientAddress : ClientsAddressList) {
            packet.setAddress(InetAddress.getByAddress(clientAddress));
            transceiverSocket.send(packet);
      }
    

提交回复
热议问题