基于Linux Socket 简单学生信息管理系统Server程序(2)


printf("name=%s,age=%d,height=%d,sex=%c",\
head->std.name,head->std.age,head->std.height,head->std.sex);
if((fd=open("/home/fcf/socket/student.txt",O_CREAT|O_APPEND|O_RDWR,0666))<0)
{
perror("open:");
exit(1);
}
else
{
printf("open file:%d\n",fd);
}
if(( W_size = write(fd,head,NODE_LEN))<0)
{
perror("write:");
exit(1);
}
// printf("name=%s,age=%d,height=%d,sex=%c",\
// head->std.name,head->std.age,head->std.height,head->std.sex);
close(fd);
break;
case'd':delete_by_name(head,recv_stu.name);
break;
case's':
s_search_data=search_by_name(head,recv_stu.name);
printf("\n");
if(s_search_data!=NULL)
{
// break;
// }
if(send(client_fd,s_search_data,sizeof(node),0)==-1)
{
perror("send");
exit(1);
}
}

else
{
printf("no data:\n");
break;
}
break;
case'p':print_list(head);//print all students information
break;
default:break;
//send(client_fd,&send_error_buf,sizeof(send_error_buf),0);
// exit(1);
}
} if(send(client_fd,&recv_stu,sizeof(struct student),0)==-1) {
perror("send");
exit(1);
}


printf(" sever:\n");
print_list(insert_from_head(head,&recv_stu));
// }


// printf("name=%s\nage=%d\nheight=%d\nsex=%c\n",\
// recv_stu.name,recv_stu.age,recv_stu.height,recv_stu.sex);
close(sockfd);
}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wyjjzy.html