Created
August 27, 2017 14:23
-
-
Save tr1379/1c47b233f8e3db3f36a7ac8bfc7d0748 to your computer and use it in GitHub Desktop.
TCP_Client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <sys/types.h> | |
#include <netinet/in.h> | |
#include <sys/socket.h> | |
#include <errno.h> | |
#include <stdlib.h> | |
#include <arpa/inet.h> | |
int main(int argc,char **argv) | |
{ | |
struct sockaddr_in s_addr; | |
int sock; | |
int addr_len; | |
int len; | |
char buff[]="SETUP rtsp://172.19.200.13:556 RTSP/1.0\r\n"\ | |
"Require: com.comcast.ngod.s6\r\n"\ | |
"SessionGroup: SM3\r\n"\ | |
"Transport: MP2T/DVBC/QAM;unicast;client=0000011BD330;bandwidth=3750912;qam_name=20168;modulation=QAM64\r\n"\ | |
"StreamType: mpts\r\n"\ | |
"CSeq: 1\r\n"\ | |
"User-Agent: ngod.s6\r\n"\ | |
"OnDemandSessionId: 880751183026832\r\n"\ | |
"\r\n"; | |
/*创建socket*/ | |
if((sock=socket(AF_INET,SOCK_STREAM,0))==-1) | |
{ | |
perror("socket"); | |
exit(errno); | |
} | |
else | |
{ | |
printf("socket created success!!!\n"); | |
} | |
/*设置目标地址及端口*/ | |
s_addr.sin_family=AF_INET; | |
s_addr.sin_port=htons(554); | |
s_addr.sin_addr.s_addr=inet_addr("8.8.8.8"); | |
/*connect tcp*/ | |
if(connect(sock,(struct sockaddr*) &s_addr,sizeof(s_addr))!=0) | |
{ | |
perror("Connect failure"); | |
exit(errno); | |
} | |
else | |
printf("server connected!\n"); | |
/*发送接收*/ | |
send(sock,buff,sizeof(buff)-1,0); | |
recv(sock,buff,sizeof(buff)-1,0); | |
buff[sizeof(buff)-1]=0; | |
printf("%s",buff); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment