首页 > 其他 > 详细

项目报告140303(补):client

时间:2014-03-07 14:13:20      阅读:503      评论:0      收藏:0      [点我收藏+]

client端两个函数已经完成,其中上传测试成功(仅client部分),下载未测试

bubuko.com,布布扣
 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <sys/types.h>
 4 #include <sys/socket.h>
 5 #include <arpa/inet.h>
 6 #include "message.h"
 7 
 8 int AddNode(int sockfd,const Node *node_ptr,int client_num)
 9 {
10     Message upd;
11     upd.op=0;//0 means update
12     upd.client_num=client_num;
13     memcpy(&upd.node,node_ptr,sizeof(Node));//copy the node to the message packaage
14     
15     int n=send(sockfd,&upd,sizeof(Message),MSG_WAITALL);
16     if(n<0)
17     return 1;
18     return 0;
19 }
20 
21 
22 int GetNode(int sockfd,Node *node_ptr,int client_num)
23 {
24     Message fet;
25     fet.op=1;//1 means get info from server
26     fet.client_num=client_num;
27     memcpy(&fet.node,node_ptr,sizeof(Node));
28 
29     int n=send(sockfd,&fet,sizeof(Message),MSG_WAITALL);
30     if(n<0)
31     {
32     printf("Send Message Error!\n");
33     return 1;
34     }
35 
36     n=recv(sockfd,&fet,sizeof(Message),MSG_WAITALL);
37     if(n<0||fet.client_num!=client_num)
38     {
39     printf("Wrong Message!\n");
40     return 1;
41     }
42 
43     memcpy(node_ptr,&fet.node,sizeof(Node));
44 
45     return 0;
46 }
bubuko.com,布布扣

项目报告140303(补):client,布布扣,bubuko.com

项目报告140303(补):client

原文:http://www.cnblogs.com/keepcalmandcarryon/p/3584974.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!