#include <iostream>
#include<sys/types.h>
#include<sys/socket.h>
#include<arpa/inet.h>
#include<netinet/ip.h>
#include<unistd.h>
#include<string.h>
#include <ctype.h>
using namespace std;
int main()
{
struct sockaddr_in server_addr;
bzero(&server_addr,sizeof(server_addr));
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(8888);
server_addr.sin_addr.s_addr = htonl(INADDR_ANY);
int sockid = socket(AF_INET,SOCK_STREAM,0);
if(sockid <0 )
{
perror("socket is error\n");
return -2;
}
if(connect(sockid,(struct sockaddr*)&server_addr,sizeof(server_addr))<0)
{
perror("connetc is error\n");
return -3;
}
char write_buf[1024]={0};
char read_buf[1024]={0};
while(cin>>write_buf)
{
int write_num = write(sockid,write_buf,strlen(write_buf));
if(write_num<0)
{
perror("write is error\n");
continue;
}
read(sockid,read_buf,sizeof(read_buf));
cout<<"printf read_buf: "<<read_buf<<endl;
}
return 0;
}