#include

#include

#include

#include

#include

#include

int main(int argc,char * argv[])

{

int sock;

char buf[20];

struct sockaddr_in serv_adr;

if(argc != 3)

{

printf("请重新运行程序,输入 “IP地址” 和 “端口号” !~\n");

exit(1);

}

sock = socket(PF_INET,SOCK_STREAM,0);

memset(&serv_adr,0,sizeof(serv_adr));

serv_adr.sin_family = AF_INET;

serv_adr.sin_addr.s_addr = inet_addr(argv[1]);

serv_adr.sin_port = htons(atoi(argv[2]));

connect(sock,(struct sockaddr *)&serv_adr,sizeof(serv_adr));

read(sock,buf,sizeof(buf)-1);

printf("%s\n", buf);

close(sock);

return 0;

}