Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Python server only receives initial chunk of UDP Datagram from writeDatagram
Forum Updated to NodeBB v4.3 + New Features

Python server only receives initial chunk of UDP Datagram from writeDatagram

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 249 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rsison
    wrote on last edited by rsison
    #1

    Hello, I've made a simple datagram that sends the contents of a byte array (Eventually an entire picture) into a python udp server on the same computer for testing reasons.

    // other code before this
        qInfo() << s1;
        socket.writeDatagram(s1.data(), QHostAddress(""), 80); // address removed due to paranoia
    

    Here is the python tester file.

    from socket import *
    serverPort = 80
    serverSocket = socket(AF_INET, SOCK_DGRAM)
    serverSocket.bind(('', serverPort))
    print('Send the picture')
    while True:
     message, clientAddress = serverSocket.recvfrom(1024)
     print(message) // check if the datagram was received properly
    

    And here is what I receive in the console after initializing the tester and sending a datagram over.

    Send the picture
    b'BM\x92\xe0\x03' // way too short, only the first four sections out of A LOT
    

    This is far too short and tiny compared to how large the text the qInfo gives me in the QT Creator console.

    I realize at this point there might be limits to how much the writeDatagram function can send, and I was hoping if I could be linked a guide or two on how to send an entire Image via a datagram via byte arrays or simply on how to send extensively large bytearrays over UDP.

    Thank you.

    JonBJ 1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      What data type is 's1' ? If it's a QByteArray then this overload is used: https://doc.qt.io/qt-6/qudpsocket.html#writeDatagram-2 - and then QByteArray is created from a const char * with this ctor: https://doc.qt.io/qt-6/qbytearray.html#QByteArray-3

      --> "If size is negative, data is assumed to point to a '\0'-terminated string and its length is determined dynamically."

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      R 1 Reply Last reply
      1
      • Christian EhrlicherC Christian Ehrlicher

        What data type is 's1' ? If it's a QByteArray then this overload is used: https://doc.qt.io/qt-6/qudpsocket.html#writeDatagram-2 - and then QByteArray is created from a const char * with this ctor: https://doc.qt.io/qt-6/qbytearray.html#QByteArray-3

        --> "If size is negative, data is assumed to point to a '\0'-terminated string and its length is determined dynamically."

        R Offline
        R Offline
        rsison
        wrote on last edited by rsison
        #3

        @Christian-Ehrlicher Yes, it is a QByteArray - It takes shape properly when displayed in qInfo().

        "BM\x92\xE0\x03\x00\x00\x00\x00\x00""6\x00\x00\x00(\x00\x00\x00\x19\x01\x00\x00-\x01\x00\x00\x01\x00\x18\x00\x00\x00\x00\x00\
        // etc
        

        I don't quite know where to 'fix' or 'begin'.
        On a side note would changing it from a BM (.bmp) to a .png make it easier in the long run to handle?

        jsulmJ 1 Reply Last reply
        0
        • R rsison

          @Christian-Ehrlicher Yes, it is a QByteArray - It takes shape properly when displayed in qInfo().

          "BM\x92\xE0\x03\x00\x00\x00\x00\x00""6\x00\x00\x00(\x00\x00\x00\x19\x01\x00\x00-\x01\x00\x00\x01\x00\x18\x00\x00\x00\x00\x00\
          // etc
          

          I don't quite know where to 'fix' or 'begin'.
          On a side note would changing it from a BM (.bmp) to a .png make it easier in the long run to handle?

          jsulmJ Online
          jsulmJ Online
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @rsison said in Python server only receives initial chunk of UDP Datagram from writeDatagram:

          I don't quite know where to 'fix' or 'begin'.

          Simply do:

          socket.writeDatagram(s1, QHostAddress(""), 80);
          

          "would changing it from a BM (.bmp) to a .png make it easier in the long run to handle?" - in what sense easier? PNG will probably result in smaller files.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          3
          • R rsison

            Hello, I've made a simple datagram that sends the contents of a byte array (Eventually an entire picture) into a python udp server on the same computer for testing reasons.

            // other code before this
                qInfo() << s1;
                socket.writeDatagram(s1.data(), QHostAddress(""), 80); // address removed due to paranoia
            

            Here is the python tester file.

            from socket import *
            serverPort = 80
            serverSocket = socket(AF_INET, SOCK_DGRAM)
            serverSocket.bind(('', serverPort))
            print('Send the picture')
            while True:
             message, clientAddress = serverSocket.recvfrom(1024)
             print(message) // check if the datagram was received properly
            

            And here is what I receive in the console after initializing the tester and sending a datagram over.

            Send the picture
            b'BM\x92\xe0\x03' // way too short, only the first four sections out of A LOT
            

            This is far too short and tiny compared to how large the text the qInfo gives me in the QT Creator console.

            I realize at this point there might be limits to how much the writeDatagram function can send, and I was hoping if I could be linked a guide or two on how to send an entire Image via a datagram via byte arrays or simply on how to send extensively large bytearrays over UDP.

            Thank you.

            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by
            #5

            @rsison
            As @Christian-Ehrlicher and @jsulm have said here. It is worth mentioning that this is effectively the same question with the same answer from @Bonnie over at your other thread https://forum.qt.io/post/821765.

            1 Reply Last reply
            2

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved