Results 1 to 5 of 5

Thread: Image transfer using QTcpsocket

  1. #1
    Join Date
    Jun 2015
    Posts
    2
    Platforms
    Unix/X11

    Default Image transfer using QTcpsocket

    Hello Experts!

    Can anybody guide how to transfer image over QTcpsocket.

    I am able to send image using code:
    QByteArray read ;
    inputFile.open(QIODevice::ReadOnly);
    while(1)
    {
    read.clear();
    read = inputFile.read(inputFile.size());
    qDebug() << "Read : " << read.size();
    if(read.size()==0)
    break;
    qDebug() << "Written : " << socket->write(read);
    socket->waitForBytesWritten();
    read.clear();
    }

    But how to read and save image on client side??

  2. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Image transfer using QTcpsocket

    Are your images available via http?

    Typically you would use QNetworkAccessManager, QNetworkRequest, and QNetworkReply to perform a QNetworkAccessManager::get request to retrieve an image over the network.

    Unless you have a specialized server listening for network requests that receive an image filename and send the binary contents to the client, I suspect what you want is to issue the get request as described above.

  3. #3
    Join Date
    Jun 2015
    Posts
    2
    Platforms
    Unix/X11

    Default Re: Image transfer using QTcpsocket

    Thanks for your reply..

    I am working client server app..
    Chat is working properly even i am able transfer text file..
    But facing problem with image..

  4. #4
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Image transfer using QTcpsocket

    So if you want to write your own server that sends images to clients, you'll need to do the following:

    For the server:

    • Use QTcpServer and listen to a known TCP/IP port number greater than 1024
    • Read the image filename sent by the client and verify it exists
    • Open the image file, read the binary data and send to the client
    • Close the connection to the client once the data is sent


    For the client:

    • Use QTcpSocket and connect to the server via ip addr or hostname and known port that server is listening to
    • Send the image filename you want to receive to the server
    • Read data from the socket and save to local file
    • Close the file once the server closes the connection


    Since TCP/IP is stream oriented, you will typically precede each request with some metadata about the data that follows so that you can determine when you have received a complete request. For example, I'd precede the actual image data with the length of the image file, so you can verify you receive the full image file, etc.

    If you don't know how to get started, you have a challenge ahead of you. Google around for some Qt TCP/IP client/server examples and study the examples provided by Qt as well.

    Good luck.

  5. #5
    Join Date
    May 2015
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Smile Re: Image transfer using QTcpsocket


Similar Threads

  1. Replies: 0
    Last Post: 18th August 2011, 04:36
  2. QTcpSocket gzip and Transfer chunked
    By giusepped in forum Qt Programming
    Replies: 0
    Last Post: 10th August 2011, 16:41
  3. QTcpSocket problem in file transfer
    By omprakash in forum Qt Programming
    Replies: 6
    Last Post: 25th January 2010, 08:18
  4. File Transfer with QTcpServer and QTcpSocket
    By NoRulez in forum Qt Programming
    Replies: 2
    Last Post: 21st October 2009, 17:12
  5. QTcpSocket & transfer errors
    By jkam in forum Qt Programming
    Replies: 1
    Last Post: 20th July 2008, 20:42

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.