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; } ////////////////////////////////////////////////////////////////////////////
i receiving 180 byte data packet continuosly (byte byte) in
rtpbuf(buffer)
usingrecvfrom()
on socket (sock1).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
Post a Comment