PDA

View Full Version : packet fragmentation and reunit!


Aben821
05-22-2003, 06:22 AM
hello,everyone! thanks in advance!
now i will send a pakcet size over 65536,and now i take the measure to divide the packet into fragmentation in the server.and i reunite them in the client.is there anyquestion here?the following is the part of source code .
/******************server************************** ***/
notes: PACKET ----->#define PACKET 32768 FRAGMENT SIZE
num ------>the number of fragmentation
other ------->rest of
num=videoSampleSize/PACKETSIZE;
other=videoSampleSize%PACKETSIZE;
--------------------------------------------------------------------------------

if(num==0)
{
memcpy(&(buf[i]),videoSampleBuf,videoSampleSize);
sendto(sockfd, buf,i+videoSampleSize , 0,(struct sockaddr *) &theiraddr, tolen);
// printf("******************** succeed send the data when num==0\n");
}
else{ //exit(0);
for(j=0;j<num+1;j++)
{
if(j==0)
{ memcpy(&(buf[i]),videoSampleBuf,PACKETSIZE);
cnt=sendto(sockfd, buf, PACKETSIZE, 0,(struct sockaddr *) &theiraddr, tolen);
sndbufsize+=cnt;
}

else
if(j==num)
{ memcpy(buf2,&videoSampleBuf[j*PACKETSIZE],other);
cnt=sendto(sockfd, buf2, other, 0,(struct sockaddr *) &theiraddr, tolen);
sndbufsize+=cnt;
printf("*******************succeed send the data %d\n",sndbufsize);
// exit(0);
}else
{
memcpy(buf2,&videoSampleBuf[j*PACKETSIZE],PACKETSIZE);
cnt=sendto(sockfd, buf2, PACKETSIZE, 0,(struct sockaddr *) &theiraddr, tolen);
sndbufsize+=cnt;
}
//usleep(1); //waiting the packet send out
}
}

/***********************client********************* ****/

if(num==0)
{
memcpy(videoSampleBuf,&(pkbuf[pkbufsize-s.size]),s.size);
// printf("succeed get data when num==0\n");
}else
{
printf("num is %d\n",num);
for(cnt=0;cnt<num+1;cnt++)
{
if(cnt==0)
{
//recvfrom(sockfd, pkbuf, PACKETSIZE, 0,(struct sockaddr *)&tmpaddr, &tmplen);
memcpy(videoSampleBuf,&(pkbuf[pkbufsize-s.size]),PACKETSIZE);
printf("get the data when num=%d\n",cnt);
}
else if(cnt==num)
{
recvsize=recvfrom(sockfd, bakbuf, other,0,(struct sockaddr *)&tmpaddr, &tmplen);
pkbufsize=pkbufsize+recvsize;
memcpy(&(videoSampleBuf[cnt*PACKETSIZE]),bakbuf,other);
printf("get the data when num=%d\n",cnt);
printf("succedd to get data %d\n",pkbufsize);
// printf("the rearrange the array is %d\n",strlen(videoSampleBuf));
// exit(0);
}
else
{
recvsize=recvfrom(sockfd, bakbuf, PACKETSIZE, 0,(struct sockaddr *)&tmpaddr, &tmplen);
pkbufsize=pkbufsize+recvsize;
memcpy(&(videoSampleBuf[cnt*PACKETSIZE]),bakbuf,PACKETSIZE);
// printf("get the data when num=%d\n",j);
}
}

Loco
06-04-2003, 11:16 PM
I quite don't understand what you are asking...

Can you please explain what you need help on?

And, if possible, please use the [[code]] tag to make the code easier to read.