69,371
社区成员
发帖
与我相关
我的任务
分享
int main(int argc ,char **argv)
{
if(argc < 2)
{
printf("the argv is not enough\n");
return 0;
}
int cli_fd;
struct sockaddr_in sevaddr;
sevaddr.sin_family = AF_INET;
sevaddr.sin_port = htons(8554);
sevaddr.sin_addr.s_addr = inet_addr(argv[1]);
//以上设置server地址信息
cli_fd = socket(AF_INET,SOCK_STREAM,0);
if(-1 == cli_fd)
{
printf("client socket set up fail,please check it\n");
return 0;
}
int resault;
resault = connect(cli_fd,(struct sockaddr*)(&sevaddr),sizeof(sevaddr)); //链接服务器
if(-1 == resault)
{
printf("connect the server fail,please check it\n");
return 0;
}
printf("connect server scucess\n");
//rtsp服务器接受的命令数据
char optionbuf[1000] = {"OPTIONS rtsp://192.168.1.104:8554/nxn.mp3 RTSP/1.0 \r\n \
CSeq: 1 \r\n\r\n \
User-Agent: live555 \r\n"};
char describebuf[1000] = {"DESCRIBE rtsp://192.168.1.104:8854/nxn.mp3 RTSP/1.0 \r\n \
CSeq: 2 \r\n \
Accept: application/sdp \r\n\r\n \
User-Agent: live555 \r\n"};
char recvbuf[1000] = {0} ;
/////////////////////////
if(sendto(cli_fd,optionbuf,sizeof(optionbuf),0,NULL,NULL) == -1)
{
printf("send data to server has take error\n");
return 0;
}
if(recvfrom(cli_fd,recvbuf,sizeof(recvbuf),0,NULL,NULL) == -1)
{
printf("recv data from server take error\n");
return 0;
}
printf("%s\n",recvbuf);
memset(recvbuf,0,1000);
if(sendto(cli_fd,describebuf,sizeof(describebuf),0,NULL,NULL) == -1)
{
printf("send data to server has take error\n");
return 0;
}
if(recvfrom(cli_fd,recvbuf,sizeof(recvbuf),0,NULL,NULL) == -1)
{
printf("recv data from server take error\n");
return 0;
}
printf("%s\n",recvbuf);
return 0;
}