public static DatagramPacket buildPacket ( PacketType type , ByteBuffer deviceName , ByteBuffer payload ) { ByteBuffer content = ByteBuffer . allocate ( 0x1f + payload . remaining ( ) ) ; content . put ( getMagicHeader ( ) ) ; content . put ( type . protocolValue ) ; content . put ( deviceName ) ; content . put ( payload ) ; return new DatagramPacket ( content . array ( ) , content . capacity ( ) ) ; }
Build a standard - format UDP packet for sending to port 50001 or 50002 in the protocol .