PDA

View Full Version : Help to send bytes



Niunzin
5th January 2014, 23:49
Hi everybody.

How i can send this packet: 00 00 00 0a 1c 01 00 00 00 22 in writeDatagram?

I tried it:

socket->writeDatagram(QByteArray("\x00\x00\x00\n\x1c\x01\x00\x00\x00\x22"), QHostAddress("37.59.46.220"), 443);

but doesn't works :(

please help me
thanks!

wysota
6th January 2014, 00:10
\x00 is an end-of-string character therefore your code is equivalent to:

socket->writeDatagram(QByteArray(""), QHostAddress("37.59.46.220"), 443);

There is a QByteArray constructor that takes both a character array and size of that array.

Niunzin
6th January 2014, 00:15
\x00 is an end-of-string character therefore your code is equivalent to:

socket->writeDatagram(QByteArray(""), QHostAddress("37.59.46.220"), 443);

There is a QByteArray constructor that takes both a character array and size of that array.

socket->writeDatagram(QByteArray("\x0a\x1c\x01\x22"), QHostAddress("37.59.46.220"), 443);
this?

ChrisW67
6th January 2014, 00:36
No, wysota was referring to the QByteArray constructor:


QByteArray ( const char * data, int size )

If you do not supply the size then the data argument is assumed to be a \0 terminated string. With your example data that means a zero length string. This is closer to the mark:


socket->writeDatagram(QByteArray("\x00\x00\x00\n\x1c\x01\x00\x00\x00\x22", 10), QHostAddress("37.59.46.220"), 443);

or you could use the other form of the writeDatagram() call.

BTW: It seems unlikely that you would have a UDP listener on the well known HTTPS port number (although it is reserved for HTTPS over UDP).

davidovv
6th January 2014, 10:19
or you can use fromPercentEncoding like in example
QByteArray::fromPercentEncoding("Qt%20is%20great%33");

Niunzin
6th January 2014, 22:30
Solved, thanks.