how to break a message into multiple (messages) to send over udp connection (android)
<p>I was wondering how can I break a message into multiple messages of 15 characters and send it over udp connection.
and how can I make the first message to be sent is the number of packets(messages to be sent)
right now I can only send one packet</p>

<pre><code>public class MainTalker extends Activity 
{
    private static DatagramSocket socket;
    private static DatagramPacket packet;
    private static Thread send;
    private Button cl1;
    private static EditText ed1;
    private static String msg = "Message";
    private static byte[] data = new byte[15];
    private static String TAG = "Sender UDP";
    static int count=0;
    static String[] output = new String[100] ;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_talker);

        ed1 = (EditText) findViewById(R.id.msg);
        cl1 = (Button) findViewById(R.id.send);

        try {
            socket = new DatagramSocket(11001);
            Toast toast = Toast.makeText(getApplicationContext(),"Port Opened",Toast.LENGTH_SHORT);
            toast.show();
            System.out.println("Port Opened ");
            socket.setBroadcast(true);
        } catch (Exception e) {
            System.out.println("Exception: Port not opened");
            e.printStackTrace();
            Log.e(TAG, e.getMessage());
        }

        cl1.setOnClickListener(new View.OnClickListener() 
        {
            public void onClick(View v) 
            {
                System.out.println("Button Clicked ");

                send = new sendthr();
                send.start();
            }
        });
    }

    private static class sendthr extends Thread {
        public void run()
        {
                System.out.println("Thread Started");

                String messg = ed1.getText().toString();

                for(int i=0; i&lt;messg.length(); i+=10)
                {
                    output[i] = messg.substring(i,i+10);
                    System.out.println(output[i]);
                    count++;

                if (messg == null)
                    output[i] = msg;
                data = output[i].getBytes();
                try
                { //Create packet with target host and target port
                    packet = new DatagramPacket(data,data.length,InetAddress.getByName("192.168.8.17"), 11001);
                    System.out.println("Packet Created");

                } catch (UnknownHostException e) {
                    System.out.println("Exception: Packet Created");

                    e.printStackTrace();
                    Log.e(TAG, e.getMessage());
                }

                try
                {
                    System.out.println("Sending the packet  "+ msg);
                    socket.send(packet);
                    System.out.println("Packet sent");
                } catch (IOException e) {
                    System.out.println("Exception: Packet Send");
                    e.printStackTrace();
                    Log.e(TAG, e.getMessage());
                }
                }
            }     
    }
}
</code></pre>
