Results 1 to 7 of 7

Thread: QTcpSocket problem in file transfer

  1. #1
    Join Date
    Jul 2007
    Posts
    20
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default QTcpSocket problem in file transfer

    dear friends, i have written two applications.
    One is client application using QTcpSocket class.
    Another is server application using QTcpServer class.
    I am now able to send the string from client to server and viceversa as well.
    i have used QDatastream object, normally what has been given in fortune client example.

    Now i want to send a file from client to server. But i am not getting how should i start the coding for the file transfer from client to server.....

    Plz help me yaar..

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTcpSocket problem in file transfer

    What have you already tried?

  3. #3
    Join Date
    Jul 2007
    Posts
    20
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTcpSocket problem in file transfer

    dear friend
    i have tried only sending small strings between two applications.
    That is a small message is sent from client application to server and vice versa..
    in client i have used QTcpSocket and in server i have used QTcpServer class..
    Just as given in fortuneClient and FortuneServer example.
    But i need help in transfering a file from client server..
    so plz hellp me..

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTcpSocket problem in file transfer

    So why don't you do it the same way?

  5. #5
    Join Date
    Jul 2007
    Posts
    20
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTcpSocket problem in file transfer

    i have used code like below for sending the string.
    Qt Code:
    1. QByteArray block;
    2. QDataStream out( &block, QIODevice::WriteOnly );
    3. out.setVersion(QDataStream::Qt_4_0);
    4. out<<"SomeString";
    5. out.device()->seek(0);
    6. out << (quint16)(block.size() - sizeof(quint16));
    7. tcpsocket->write(block);
    To copy to clipboard, switch view to plain text mode 

    Now just hint me what should i insert into code for my file transfer...
    bye
    Last edited by jpn; 12th May 2008 at 13:33. Reason: missing [code] tags

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTcpSocket problem in file transfer

    1. Read a chunk of file to a byte array,
    2. Write the contents of the byte array to the socket,
    3. Repeat until you reach the end of the file.

    Come on, the task is really simple - it fits more for the newbie forum and not the programming forum.

  7. #7
    Join Date
    Sep 2009
    Posts
    39
    Thanks
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QTcpSocket problem in file transfer

    Hi omprakash...
    I'm trying to send any type of File on Qt using serial port or Socket Packets. I want to know how to do it.How to add headers and footers to it.plz assist me.
    Thanking you

Similar Threads

  1. File Transfer with QTcpServer and QTcpSocket
    By NoRulez in forum Qt Programming
    Replies: 2
    Last Post: 21st October 2009, 17:12
  2. Replies: 2
    Last Post: 2nd April 2008, 17:28
  3. EXE File problem
    By triperzz in forum Installation and Deployment
    Replies: 8
    Last Post: 18th January 2008, 19:00
  4. Replies: 3
    Last Post: 29th June 2007, 08:32
  5. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 15:21

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.