- 論壇徽章:
- 0
|
#include<stdio.h>
#include<string.h>
#include<sys/socket.h>
#include<errno.h>
#include<stdlib.h>
#include<netinet/in.h>
#define MAXLINE 1024
#define MMFCPORT 80
int main(int argc,char *argv[]){
struct sockaddr_in srv;
int sock, nbytes;
if((sock = socket(AF_INET,SOCK_STREAM,0))==-1){
fprintf(stderr, "socket() error! %s \n",strerror(errno));
exit(1);
}
bzero(&srv,sizeof(srv));
srv.sin_family = AF_INET;
srv.sin_addr.s_addr = htons(INADDR_ANY);
srv.sin_port = htons(MMFCPORT);
if((connect(sock,(struct sockaddr *)&srv,sizeof(struct sockaddr))) == -1){
printf("connect() error! %s\n",strerror(errno));
exit(1);
}
char recbuf[MAXLINE+1];
while((nbytes = read(sock,recbuf,MAXLINE))!=0){
recbuf[nbytes] = '\0';
printf("%s",recbuf);
}
printf("response end\n");
close(sock);
return 0;
}
執(zhí)行結(jié)果
mmxcq@ubuntu:~/下載/hightall$ ./client
response end
mmxcq@ubuntu:~/下載/hightall$
我是想去獲取apache的http://127.0.0.1的內(nèi)容
大家?guī)兔χ刚幌挛业腻e誤阿 謝謝 |
|