我正在尝试将文件从客户端流式传输到服务器,但是从 FILE 到 char 的数据类型不兼容,因此每次运行客户端时都会出现分段错误。我不知道如何解决这个问题。附件是服务器和客户端的代码,下面是客户端的问题。我正在尝试从客户端读取文件到缓冲区将其发送到服务器,服务器将从缓冲区读取文件并将其写入文件。客户端 http://pastebin.com/QtLbMgP3
服务器端 http://pastebin.com/8PNchBUZ
// n = write(sock,"send me your message",18);
printf("Please enter the message: ");
bzero(buffer,256);
fgets(buffer,255,stdin);
ptr_myfile=fopen("test2.txt","w");
for(counter=1;counter <=10;counter++){
fwrite(&ptr_myfile,sizeof(*buffer),1,buffer);
n = read(sockfd,buffer,255);
n = write(sockfd,buffer,18);
n = write(sockfd,buffer,strlen(buffer));
if (n < 0) error("ERROR writing to socket");
bzero(buffer,256);
n = read(sockfd,buffer,255);
if (n < 0) error("ERROR reading from socket");
// printf("%s\n",buffer);
};//close for loop
close(sockfd);
}// close event loop
return 0;
}// close main function