Send files over network

  • Hello,
    I want to create a chat for exchanging text and files too (photos, videos ...). Thus, each participant sends each participant text and files.
    I do not know how to organize it.
    I think setting up a peer to peer architecture. I found a tutorial ("here": to send text by peer to peer. However, I do not find how to send files.

    Does someone could help me achieve this?

    Thank you all.

  • Moderators

    QTcpSocket inhertits from QIODevice, which can send any type of binary data. That means you can use QDataStream.

  • Ok, but in the tutorial, they use QUdpSocket instead of QTcpSocket. Can I use QDataStream with QUdpSocket ?
    In addition, do QDataStream allow me to send files and text or do I create 2 different sockets?
    If yes, I guess I just have to replace QString by QDataStream in the 'sendMessage' function, isn't it?

  • Moderators

    Just check out the documentation, please. QUdpSocket and QTcpSocket both inherit from QAbstractSocket, which inherits from QIODevice.

    You can use the same socket to send and receive text and binary data. It is your responsibility, however, to properly parse the data at the receiving end.

    Also, please remember that UDP protocol is stateless and does not guarantee the order the packets come in. It also does not warn on transmission errors.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.