Hi All,
HW: DM814x
SW: ipnc v3.2
I am streaming H264 encoded video over RTSP. VLC player able to receive this stream and play it properly.
But, I want to write a custom socket app, which can look into my port & ip of the board , receive data & dump to a File.
I wrote below code to achieve that. It successfully creates sockets, connects & then waits in receive from function without receiving any packets. I don have any clue WHY IT WAITS in recvfrom()? It will be great if some one can help me here.
/********************************************************** My udp scoket(receiver) code**********************************************************************/
/* Creates a datagram server. The port number is passed as an argument. This server runs forever */
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdio.h>
#include <unistd.h> /* close() */
#include <string.h> /* memset() */
#include <stdlib.h>
#include<time.h>
#define SIZE_IN_BYTES 1500
/* This IP & port represents Ip & port of Board */
#define IPADDR "192.168.1.109"
#define PORT 8557
void error(char *msg)
{
perror(msg);
exit(0);
}
int main(int argc, char *argv[])
{
int sock, length, fromlen, n;
struct sockaddr_in server;
struct sockaddr_in from;
char buf[SIZE_IN_BYTES];//1500
static int count=0,frame=0;
static int inTime=0, outTime=0;
unsigned short disp;
int ret;
if (argc < 2)
{
fprintf(stderr, "ERROR, no port provided\n");
exit(0);
}
sock=socket(AF_INET, SOCK_STREAM, 0);
if (sock < 0)
{
error("Opening socket");
}
int val=1;
int ret1=setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,(const int *)(&val), sizeof val);
if(ret1<0)
{
printf("ERR in set opt\n\n");
exit(1);
}
length = sizeof(server);
bzero(&server,length);
server.sin_family=AF_INET;
server.sin_port=htons(atoi(argv[1]));
if (inet_aton(IPADDR, &server.sin_addr)==0)
{
fprintf(stderr, "inet_aton() failed\n");
exit(1);
}
if (connect(sock,(struct sockaddr *)&server,length)<0)
{
error("pathpartner connect: ");
}
fromlen = sizeof(struct sockaddr_in);
while (1)
{
n = recvfrom(sock,buf,SIZE_IN_BYTES,0,(struct sockaddr *)&from,&fromlen);
if (n < 0)
{
error("recvfrom");
exit(0);
}
else
{
frame++;
printf("\nreceived data count=%d,frames=%d\n",count,frame);
}
}
}