how to handle bytestream data in c socket -


void *rtp_rec() {     memset(rtpbuf, 0, sizeof(rtpbuf));     unsigned char rtpbuf[2024]="";     while(1)     {         receive = recvfrom(sock1, rtpbuf,sizeof(rtpbuf) ,0,(struct sockaddr*)&serverrtp,(socklen_t*)&sizeof(serverrtp););         n = sendto(sock2,rtpbuf,strlen(rtpbuf),0,(struct sockaddr *)&sendtoother,sizeof(sendtoother));     }     return 0; } //////////////////////////////////////////////////////////////////////////// 
  1. i receiving 180 byte data packet continuosly (byte byte) in rtpbuf(buffer) using recvfrom() on socket (sock1).

  2. and want send same data packet of 180 byte socket (sock2) using sendto().

but sendto() function sending 1 byte data packet, recvfrom() receving data byte byte.

please suggest logic.

you need check value of recvfrom() make sure there no error, , ensure received proper number of bytes. also, want send many bytes you're receiving rather using strlen(rtpbuf) in case have null bytes in received data.

receive = recvfrom(sock1, rtpbuf,sizeof(rtpbuf) ,0,(struct sockaddr*)&serverrtp,(socklen_t*)&sizeof(serverrtp)); if (receive == -1) {     perror("recvfrom failed"); } else {     printf("received %d bytes\n", receive);     n = sendto(sock2,rtpbuf,receive,0,(struct sockaddr *)&sendtoother,sizeof(sendtoother)); } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -