Results 1 to 14 of 14

Thread: File transfer through sockets

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: File transfer through sockets

    Quote Originally Posted by Quenix View Post
    Thank you very much for your example. It helps me a lot to introduce me to QT code and TCP data transfer too. (I'm a student)

    I tried your code for a basic project at school : transfer a movie from a server to a client and play it on the client side.
    I just have to made some modification to your code in order to make it work properly.

    1. I had to write a waitForReadyRead in the client side because it doesn't do anything when the SIGNAL(readyRead()) happens
    No. The client example code was even driven, no need to call any waitForXYZ. Whenever something happens on the socket, e.g. data received, a signal will be emitted and the client code reacts to that. In the example code it reads the available data and appends it to the file.

    Your modification effetively blocks the ClientReadData() method until all data has been transferred, totally blocking the thread that executes it, needlessly introducing the need for a thread in order not to block the main thread.

    There is no need for threading here at all, it just complicates the two programs and makes them harder to debug.

    Cheers,
    _

  2. #2
    Join Date
    May 2013
    Location
    Quebec, Canada
    Posts
    7
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: File transfer through sockets

    Quote Originally Posted by anda_skoa View Post
    No. The client example code was even driven, no need to call any waitForXYZ. Whenever something happens on the socket, e.g. data received, a signal will be emitted and the client code reacts to that. In the example code it reads the available data and appends it to the file.
    Thank you very much for your answer.

    What should I use instead of a client->waitForSomething because without this, nothing happens in the client side after the initial TCP Handshake when the server started to write in the socket.

    Quote Originally Posted by anda_skoa View Post
    Your modification effetively blocks the ClientReadData() method until all data has been transferred, totally blocking the thread that executes it, needlessly introducing the need for a thread in order not to block the main thread.

    There is no need for threading here at all, it just complicates the two programs and makes them harder to debug.
    The only way I see to do it better is to introduce a new threads, but that's because I'm a beginner ;-)
    How could it be written in a better way ?

    Thank you,

    --
    Serge

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: File transfer through sockets

    Check that you have started the main thread's event loop, i.e. called exec() on the application object.

    Cheers,
    _

  4. #4
    Join Date
    May 2013
    Location
    Quebec, Canada
    Posts
    7
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: File transfer through sockets

    Quote Originally Posted by anda_skoa View Post
    Check that you have started the main thread's event loop, i.e. called exec() on the application object.
    I tried the code in a QT application with GUI and I create the Class Client object with a button.clicked(). When I click on the button, I thought that the QApplication::exec() happens in the main.cpp before I pressed on the button. So, normally, the main thread's event loop is supposed to be started before I click anywhere on the mainwindow .?

    Thank you very much for the time you take to answer all my newbe question :-)

    --
    Serge

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: File transfer through sockets

    Yes, if you have a working GUI then the eventloop should be running.

    Hard to tell without a minimal program using the concrete code.
    All signal/slots setup correctly?

    Cheers,
    _

  6. #6
    Join Date
    May 2013
    Location
    Quebec, Canada
    Posts
    7
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: File transfer through sockets

    Quote Originally Posted by anda_skoa View Post
    All signal/slots setup correctly?
    This is exactly the code you can see upper.
    For the rest, there's just 1 button in the client side and I used "Go to slot..." in qtdesigner to create the SIGNAL/SLOT connection.

    thanks,
    Serge

  7. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: File transfer through sockets

    Well, since you claim this is all the code and the code does not contain any signal/slot connects, you are obviously missing those.

    Cheers,
    _

Similar Threads

  1. Replies: 1
    Last Post: 11th February 2011, 04:32
  2. File Transfer in Qt
    By Rajeshsan in forum Qt Programming
    Replies: 6
    Last Post: 11th February 2011, 04:13
  3. Replies: 2
    Last Post: 2nd April 2008, 17:28
  4. how to send a file over qt4 tcp sockets?
    By sha3er in forum Qt Programming
    Replies: 1
    Last Post: 11th June 2007, 16:57

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
  •  
Qt is a trademark of The Qt Company.