Sending and Receiving an integer array through TCP connection
Hey,
I was wondering if anyone could help me with this, I am able to write a string and receive the string but I would like it to be an integer array instead. I am using QTcpSocket to create the connection between the client and server.
The following is the coding I am using for sending the string over
Code:
client.write("hello", 5);
And the following is the code I am using for receiving the string
Code:
char buffer [1024] = {0};
client.read(buffer, client.byteAvailable());
Thanks,
Strateng
Re: Sending and Receiving an integer array through TCP connection
Use QDataStream to implement a real protocol. Have a look at the Fortune Client example.
Re: Sending and Receiving an integer array through TCP connection
Hey,
Oh okay. I was looking through that but I was also wondering would it be possible to use QTcpSocket and QNetwork to connect to another program using TCP connection that is written in C++ but not with QT sending the integer array? And if so, would you be able to provide an example coding of it?
Thanks,
Strateng
Quote:
Originally Posted by
spud
Re: Sending and Receiving an integer array through TCP connection
You can access the data like this if both systems have the same endianess.
Code:
int* data = reinterpret_cast<int*>(buffer);