PDA

View Full Version : Socket File Transfer



jmqt
15th July 2009, 14:08
I am having trouble with transferring files through sockets. When I do transfer files, the files are funky and does not reflect the original file.

My code is:

QDateTime *date = new QDateTime;
QString str="example_file_";
QString str1; str1=date->currentDateTime().toString("dd.MM.yyyyhh:mm:ss.zzz.txt");
f = str.append(str1);


const char * fpointer = f.toAscii().data();
client socket:
FILE* fp = fopen(QFile::encodeName(f),"r");
while(!feof(fp)){
//bzero(buf,sizeof(buf));
fread(buf,sizeof(char),50,fp);
write(sockfd,buf,50);
}
server socket:
FILE* fp = fopen("server.txt","w");

If anyone could assist me, it would be greatly appreciated!

mcosta
16th July 2009, 13:24
If you use fread you have to open the file in binary mode