#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <strings.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
int main()
{
int sockfd =socket(AF_INET,SOCK_STREAM,0);
if (sockfd<0)
{
perror("socket");
return -1;
}
struct sockaddr_in caddr;
caddr.sin_family =AF_INET;
caddr.sin_port=htons(9987);
caddr.sin_addr.s_addr=inet_addr("0");
bzero(&(caddr.sin_zero),8);
int ret =connect(sockfd,(struct sockaddr *)&caddr,sizeof(struct sockaddr));
if(ret<0)
{
perror("connect");
return -1;
}
char buf1[10]={0};
fgets(buf1,10,stdin);
int rws =send(sockfd,buf1,10,0);
if(rws<0)
{
perror("send");
return -1;
}
char buf[100]={0};
int ret1=recv(sockfd,buf,100,0);
if(ret1<0)
{
perror("recv");
return -1;
}
printf("result: %s\n",buf);
close (sockfd);
return 0;
}