Python server only receives initial chunk of UDP Datagram from writeDatagram
-
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.
-
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."
-
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."
@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? -
@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?@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.
-
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.
@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.