void do_cli(FILE *fp, int sockfd, struct sockaddr *pservaddr, socklen_t servlen)
{
int n;
char sendline[MAXLINE], recvline[MAXLINE + 1];
/* connect to server */
if(connect(sockfd, (struct sockaddr *)pservaddr, servlen) == -1)
{
perror("connect error");
exit(1);
}
printf("Please specify the file you want to read... [exit to EXIT]\n>> ");
while(fgets(sendline, MAXLINE, fp) != NULL)
{
if ( strcmp(sendline, "exit\n") == 0)
{
break;
}
/* read a line and send to server */
write(sockfd, sendline, strlen(sendline));
/* receive data from server */
n = read(sockfd, recvline, MAXLINE);
if(n == -1)
{
perror("read error");
exit(1);
}
recvline[n] = 0; /* terminate string */
printf("\n[[ Detailed information of the file ]] \n");
printf("=====================================\n");
fputs(recvline, stdout);
printf("\n\n");
printf("Please specify the file you want to read... [exit to EXIT]\n>> ");
}
}
int main(int argc, char **argv)
{
int sockfd;
struct sockaddr_in servaddr;