Results 1 to 2 of 2

Thread: Socket File Transfer

  1. #1
    Join Date
    Jun 2009
    Posts
    10
    Platforms
    MacOS X

    Default Socket File Transfer

    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:
    Qt Code:
    1. QDateTime *date = new QDateTime;
    2. QString str="example_file_";
    3. QString str1; str1=date->currentDateTime().toString("dd.MM.yyyyhh:mm:ss.zzz.txt");
    4. f = str.append(str1);
    5.  
    6.  
    7. const char * fpointer = f.toAscii().data();
    8. client socket:
    9. FILE* fp = fopen(QFile::encodeName(f),"r");
    10. while(!feof(fp)){
    11. //bzero(buf,sizeof(buf));
    12. fread(buf,sizeof(char),50,fp);
    13. write(sockfd,buf,50);
    14. }
    15. server socket:
    16. FILE* fp = fopen("server.txt","w");
    To copy to clipboard, switch view to plain text mode 

    If anyone could assist me, it would be greatly appreciated!
    Last edited by jpn; 16th July 2009 at 14:08. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Socket File Transfer

    If you use fread you have to open the file in binary mode
    A camel can go 14 days without drink,
    I can't!!!

Similar Threads

  1. QTcpSocket problem in file transfer
    By omprakash in forum Qt Programming
    Replies: 6
    Last Post: 25th January 2010, 08:18
  2. File Transfer with QTcpServer and QTcpSocket
    By NoRulez in forum Qt Programming
    Replies: 2
    Last Post: 21st October 2009, 17:12
  3. Replies: 2
    Last Post: 2nd April 2008, 17:28
  4. How to transfer file through serial communication
    By shamik in forum Qt Programming
    Replies: 29
    Last Post: 29th May 2007, 10:22

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.