from client:%s\n", buf);Р int wr = write(fd,buf,ret);Р if(-1 == wr)Р {?Р perror("wr error!");Р close(wr);Р return -1;Р }Р printf("Write OK!");Р exit(0);Р}Р文件上传客户端部分代码:Рint fd = open ("/home/linux/yx/client/file.txt",O_RDONLY,0666);Рwhile(1)Р{Р?bzero(buf, sizeof(buf));Р?int rd = read(fd,buf,4096);Р?if(0 == rd)Р?{Р printf("upload ok!\n");Р break;Р?}Р?send(cliFd, buf, rd, 0);Р}Р3.4文件下载程序设计与实现Р图4-文件下载模块原理图Р文件下载服务器端代码与文件上传的客户端代码原理相同,此处略。Р文件下载客户端代码与文件上传的服务器端代码原理相同,此处略。Р3.5多进程简易聊天设计与实现Р图5 –简易聊天模块原理图Р简易聊天服务器端部分代码:Рwhile(1)Р{Р?bzero(buf, sizeof(buf));Р?ret = recv(connFd, buf, sizeof(buf), 0);Р?if(0 == ret)Р?{Р printf("client shutdown!\n");Р close(connFd);Р exit(0);Р?}Р?printf("recv from client:%s\n", buf);Р?bzero(buf, sizeof(buf));Р?printf("server:");Р?gets(buf);Р?send(connFd, buf, sizeof(buf), 0);