I must develop a Client application using (Qt) C++. The server application was developed by somebody. I need to register with the Server application to get data from it. I have problems here. Can anybody please let me know how to proceed.
In order to register with the server, the client must first send a Hello instruction to it. And the format for Hello is as follows:
Length Contents Term Description
4 byte xx xx xx xx PACKET_LENGTH Length of the packet in byte
2 byte 00 01 HELLO Command Hello
1 byte 02 VERSION Version of protocol
1 byte 02 Client Type
variable xx IDENTIFICATION String to identify program
For eg., I register with the Server with following command
00 01 02 02 09 MyProgram
where 00 01 is for hello
02 is for version
02 is for Client type
08 is for length of my string (MyProgram)
How can I send the above command to Server?? What kind of data type should i use for storing this command?? Please note the data must be sent in Motorola byte order.
I tried with the following code but the server is not accepting.
QDataStream out(&block, QIODevice::WriteOnly);
qint16 hello = 0001; // I think problem is here.
short version = 02;
short clientType = 02;
QString identifier = "MyProgram";
qint8 length = identifier.size();
out << quint16(0) << hello << version << clientType << length << identifier;
out << quint16(block.size()- sizeof(quint16));
In the internet I saw examples using struct and pack in python. don't know how to use it in C++.
Thanks in advance.
Edited 7 Years Ago by thisismyuname: n/a