Hey guys,

I am not sure what is going on here or if the issue could be easily fixed or not. It might be a basic thing that I am missing.
I need to send some data over network UDP sockets so I built a "sender" and a "receiver" using QUdpSocket which worked fine.
The requirements changed and now the "sender" has to send data using Winsocks instead QUdpSocket but the "receiver" still can used QUdpSocket.
I am getting a weird output when using qDebug on the received stream. I have put together an example about how I am doing everything and
hopefully, someone will have the answer.



######### SENDING - #1
stringstream str;

str << (uint32)0;

str << (uint32)0x53486472 <<
(uint32) << 0
(uint32)1 <<
(uint32)2 <<
(uint32)3 <<
(uint32)4 <<
(uint32)5 <<
(uint32)6 <<
(uint32)7;

str << (uint32)0x54695355 <<
(char*)INFO-1 <<
(char*)869543-1 <<
(char*)85A-1 <<
(uint16)1 <<
(char*)C0B3-MV1R-1 <<
(bool)false;



char * sendbuf = new char[str.str().length() + 1];
std::strcpy(sendbuf, str.str().c_str());


struct sockaddr_in clientService;
clientService.sin_family = AF_INET;
clientService.sin_addr.s_addr = inet_addr(address);
clientService.sin_port = htons(port);


SOCKET sock = socket(clientService.sin_family, SOCK_DGRAM, IPPROTO_UDP);
connect(sock, (SOCKADDR*)&clientService, sizeof(clientService));
send(sock, sendbuf, (int)strlen(sendbuf), 0);
closesocket(sock);



######### SENDING - #2

QByteArray datagram;
QDataStream stream(&datagram, QIODevice::WriteOnly);
stream.setVersion(QDataStream::Qt_5_9);

stream << (uint32)0;

stream << (uint32)0x53486472 <<
(uint32) << 0
(uint32)1 <<
(uint32)2 <<
(uint32)3 <<
(uint32)4 <<
(uint32)5 <<
(uint32)6 <<
(uint32)7;

stream << (uint32)0x54695355 <<
(char*)INFO-1 <<
(char*)869543-1 <<
(char*)85A-1 <<
(uint16)1 <<
(char*)C0B3-MV1R-1 <<
(bool)false;


QUdpSocket *udpSocket = new QUdpSocket(this);
udpSocket->writeDatagram(datagram.data(), datagram.size(), QHostAddress::LocalHost, port);



######### RECEIVING

QUdpSocket *udpSocket = new QUdpSocket(this);

QByteArray datagram;
qint64 size = udpSocket->pendingDatagramSize();
datagram.resize(size);
udpSocket->readDatagram(datagram.data(), datagram.size());

QDataStream stream(&datagram, QIODevice::ReadOnly);
stream.setVersion(QDataStream::Qt_5_9);

qDebug() << "NetworkReceiver";
qDebug() << datagram.size();
qDebug() << datagram;





-------- Output when using SENDING #1:
NetworkReceiver
61
"01397253234012345671416188757INFO-1869543-185A-11C0B3-MV1R-10"




-------- Output when using SENDING #2:
NetworkReceiver
97
"\x00\x00\x00\x00SHdr\x00\x00\x00\x00\x00\x00\x00\ x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x0 4\x00\x00\x00\x05\x00\x00\x00\x06\x00\x00\x00\x07T iSU\x00\x00\x00\x07INFO-1\x00\x00\x00\x00\t869543-1\x00\x00\x00\x00\x06""85A-1\x00\x00\x01\x00\x00\x00\fC0B3-MV1R-1\x00\x00"