PDA

View Full Version : Server Client QDataStream and QByteArray



cafu1007
28th May 2010, 13:29
Hi there, I have a Sever Client app that do receive and send information.

I have made a struct with the important thing that are being send thru.

I have reimplemented the operator>> << for the QDataStream to put and receive transforn(serialized i think) from the struct.

but now the customer want to reimplement the client i should give away the "protocol" but i have no idea how to do this since i dont know how the serializacion is done. what can i do to achieve this?, i pretty sure that is possible since what we are sending over tcp it just data plus header, how can i know what the client is writing in the port so if he want to make the client c# ,java or whatever else is posible and i dont have to modified so bad the application. Or shall just send a byteArray with separator(need to specified one) and the tried set the value to the structs manually.

Thanks for the answers

high_flyer
28th May 2010, 14:29
Its very hard to follow on what the problem is.
Can you distill your problem description to the problem it self?

cafu1007
28th May 2010, 14:52
i want to say to the client what my server application should receive so understand what it should do. But i am not providing the client application.


Right now the client and the server i have done then,so i never care what happen when i do sth like this:



static QDataStream& operator<<(QDataStream& stream, structXX& xx)
{
stream << xx.n() <<xx.str()<<xx.ch();
}
static QDataStream& operator>>(QDataStream & stream, structXX& xx)
{
qint32 n;
QString str;
quint8 ch;
stream >> n;
stream >> str;
stream >> ch;
xx.set_n(n);
xx.set_str(str);
xx.set_ch(ch);
}

//on the socket class

qint32 socket::send(structXX &xx)
{
QByteArray block;
QDataStream stream(&block, QIODevice::WriteOnly);
stream << (qint64) 0;
stream << xx;
stream.device()->seek(0);
stream << (qint64) (block.size() - sizeof(qint64));
m_Socket->write(block);
m_Socket->flush();
block.clear();
return 0;
}
void socket::slotReadyRead()
{
structXX xx;
QDataStream stream(m_Socket);
if (m_lBlockSize == 0)
{
if (m_Socket->bytesAvailable() < (int) sizeof(qint64))
{
return;
}
stream >> m_lBlockSize;
}
if (m_Socket->bytesAvailable() < m_lBlockSize)
{
return;
}
stream >> message;
}


So now what i want is to give a set of "strings" to the customer so he can implement the client application by hes own.

thanks for answers

alexisdm
28th May 2010, 18:42
The format used by QDataStream is described there http://doc.trolltech.com/datastreamformat.html
And the default ordering for numbers is big endian.

cafu1007
31st May 2010, 11:20
Ok, thanks, but still i do not see how to say to the customer what he should send thru the tcp even though he is no using QT.

tbscope
31st May 2010, 11:58
If I understand you correctly, you should provide a document (Like a RFC) for your protocol and give it to anyone who wants to implement a client that is able to talk with your server.

cafu1007
31st May 2010, 16:41
yeah exactly, that is waht i need....