PDA

View Full Version : Conventional UNIX Socket based server receiving data from QTcpSocket... Possible?



Gavin Harper
16th December 2010, 19:40
I am working on a pair of applications that serve different system needs. The client application I have written in Qt since QWT is key though for the server, I wish to write it in standard C++ (There are circumstances that make this is preferable).

My question is simply, how best to send data from the Qt client using QTcpSocket in such a way that it is directly readable by a non Qt socket?

Thank you, I appreciate any time spent in providing insight.

hexa
16th December 2010, 20:06
I might be wrong, since I'm new to Qt and never used one of it's QSockets, but I imagine that data is data.

What I mean is, if you make a tcp connection with QTcpSocket and send 8 bytes of data, the other side will recieve 8 bytes of data, untouched.

I think you do not need to worry, it's a convenience class around sockets.

regards,
hexa

tbscope
16th December 2010, 20:11
but I imagine that data is data.

Oops :-)
Data can take a billion and one forms.
If your unix socket uses UDP and you send data via TCP, I think you might have a problem.

So, this only works if both sockets speak the same "language".

wysota
16th December 2010, 21:01
If your unix socket uses UDP and you send data via TCP, I think you might have a problem.
There will be no problem. There will simply be no communication as UDP and TCP have their own set of ports so UDP port X has nothing to do with TCP port X. There can be different services running on both of them.

ChrisW67
16th December 2010, 22:49
My question is simply, how best to send data from the Qt client using QTcpSocket in such a way that it is directly readable by a non Qt socket?
As long as you send the data using whatever format the other end requires then all will be good. If it is text data then this fairly trivial, if it is binary then you need to send it using the lower level QIODevice::write() interface. Do not use QDataStream unless you have a Qt receiver.

Gavin Harper
17th December 2010, 03:11
As long as you send the data using whatever format the other end requires then all will be good. If it is text data then this fairly trivial, if it is binary then you need to send it using the lower level QIODevice::write() interface. Do not use QDataStream unless you have a Qt receiver.

That is exactly what I needed to know! Thank you!

I was concerned that my current method of using QByteArray's and QDataStreams would render the packets incompatible.

wysota
17th December 2010, 08:38
QByteArray is fine. QDataStream has an algorithm within so you need to implement the same algorithm without Qt if you want to use it with a different technology.

Gavin Harper
18th December 2010, 12:57
So if I use QByteArray and fire that out over QTcpSocket, it can be interpreted by a standard non-Qt socket bound to a given port?

I will just (generally) be sending floating point numbers.

I need my Client application to be Qt for cross platform compatibility but the server is likely to run on a UNIX based OS with no guarantee that Qt will be available.

Thank you to everyone thus far for help!

wysota
18th December 2010, 15:07
QByteArray is just a series of bytes without any modifications.