1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
public byte[] RecevoirTabUDP(int taille_tab_final)
{
int size_max_packet=1024;
byte[] tab_src=new byte[taille_tab_final];
byte[] tableauPacket=new byte[taille_tab_final];
int nbr_packet=(int)(taille_tab_final/size_max_packet);
int taille_tab_reste=taille_tab_final-size_max_packet*nbr_packet;
DatagramPacket packetUDP;
try
{
//socketSrvUDP.setSoTimeout(5000);
for(int i=0;i<nbr_packet;i++)
{
packetUDP = new DatagramPacket(tableauPacket, tableauPacket.length);
socketSrvUDP.receive(packetUDP);
for(int j=0;j<size_max_packet;j++)
{
tab_src[i*size_max_packet+j]=tableauPacket[j];
}
packetUDP=null;
//System.arraycopy(tableauPacket,0 , tab_src, i*size_max_packet, size_max_packet);
}
if((taille_tab_final % size_max_packet) !=0)
{
//Reception du dernier packet qui va contenir un nombre de byte < 1024
byte[] tableauPacket_reste=new byte[taille_tab_reste];
packetUDP = new DatagramPacket(tableauPacket_reste, tableauPacket_reste.length);
socketSrvUDP.receive(packetUDP);
for(int k=0;k<taille_tab_reste;k++)
{
tab_src[nbr_packet*size_max_packet+k]=tableauPacket_reste[k];
}
packetUDP=null;
//System.arraycopy(tableauPacket_reste, 0, tab_src, nbr_packet*size_max_packet, taille_tab_reste);
}
}
catch(Exception e)
{
e.printStackTrace();
}
return tab_src;
} |
Partager