Postby giorgino » 26 Oct 2009 17:52
I downloaded DVBLast and I would like to write a network
client, but I have problem to establish the connection with the udp socket
opened by the DVBLast.
I wrote the following code but I don't understand were
I make wrong. the client remains stopped on the readv in the sense that doesn't receive any packets although server is transmitting.
int main(int argc, char* argv[])
{
uint8_t p_rtp_hdr
[RTP_SIZE];
input_t *p_input=NULL;
struct iovec p_iov[NB_BLOCKS + 1];
int i,p_read;
p_input = malloc( sizeof(input_t) );
int sockd
= socket(AF_INET, SOCK_DGRAM, 0);
if (sockd < 0)
{
fprintf
(stderr, "Error, socket() failed: %s\n", strerror(errno));
return 1;
}
struct sockaddr_in addr;
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
//memcpy(&addr.sin_addr.s_addr, pServer->h_addr,
pServer->h_length);
addr.sin_addr.s_addr = inet_addr(argv[1]);
addr.sin_port
= htons(1234);
int returnStatus = connect(sockd,(struct sockaddr*)&addr,
sizeof(addr));
p_iov[0].iov_base = p_rtp_hdr;
p_iov[0].iov_len = sizeof
(p_rtp_hdr);
for ( i = 1; i < NB_BLOCKS + 1; i++ )
{
block_t
*p_block = malloc(sizeof(block_t));
p_input->pp_blocks[i-1]=p_block;
p_iov.iov_base = p_input->pp_blocks[i-1];
p_iov.iov_len =
TS_SIZE;
printf("size %d \n",TS_SIZE);
}
while((p_read =
readv(sockd, p_iov, NB_BLOCKS+1)) < 0 )
{
printf("packets
read %d \n",p_read);
}//
return 1;
}
If you can help
me I will be very grateful to you.
Thanks and have a nice day