PDA

View Full Version : Sending and Receiving an integer array through TCP connection



strateng
6th April 2010, 05:49
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


client.write("hello", 5);


And the following is the code I am using for receiving the string


char buffer [1024] = {0};
client.read(buffer, client.byteAvailable());


Thanks,
Strateng

spud
7th April 2010, 14:02
Use QDataStream to implement a real protocol. Have a look at the Fortune Client (http://qt.nokia.com/doc/4.6/network-fortuneclient.html) example.

strateng
8th April 2010, 01:04
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


Use QDataStream to implement a real protocol. Have a look at the Fortune Client (http://qt.nokia.com/doc/4.6/network-fortuneclient.html) example.

spud
8th April 2010, 07:59
You can access the data like this if both systems have the same endianess.

int* data = reinterpret_cast<int*>(buffer);