Results 1 to 9 of 9

Thread: Conventional UNIX Socket based server receiving data from QTcpSocket... Possible?

  1. #1
    Join Date
    Aug 2010
    Posts
    28
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Conventional UNIX Socket based server receiving data from QTcpSocket... Possible?

    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.

  2. #2
    Join Date
    Dec 2010
    Location
    Brazil
    Posts
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Conventional UNIX Socket based server receiving data from QTcpSocket... Possible?

    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

  3. #3
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Conventional UNIX Socket based server receiving data from QTcpSocket... Possible?

    Quote Originally Posted by hexa View Post
    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".

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Conventional UNIX Socket based server receiving data from QTcpSocket... Possible?

    Quote Originally Posted by tbscope View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Conventional UNIX Socket based server receiving data from QTcpSocket... Possible?

    Quote Originally Posted by Gavin Harper View Post
    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.

  6. #6
    Join Date
    Aug 2010
    Posts
    28
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Conventional UNIX Socket based server receiving data from QTcpSocket... Possible?

    Quote Originally Posted by ChrisW67 View Post
    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.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Conventional UNIX Socket based server receiving data from QTcpSocket... Possible?

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Aug 2010
    Posts
    28
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Conventional UNIX Socket based server receiving data from QTcpSocket... Possible?

    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!

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Conventional UNIX Socket based server receiving data from QTcpSocket... Possible?

    QByteArray is just a series of bytes without any modifications.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Clear QTcpSocket buffer before using receiving new data
    By tbscope in forum Qt Programming
    Replies: 2
    Last Post: 26th February 2011, 06:50
  2. Replies: 1
    Last Post: 18th October 2010, 16:07
  3. Replies: 0
    Last Post: 31st July 2010, 17:27
  4. QUdpSocket: sending and receiving on the same socket?
    By mhoover in forum Qt Programming
    Replies: 16
    Last Post: 17th June 2009, 03:28
  5. QTcpSocket + receiving data
    By navi1084 in forum Qt Programming
    Replies: 1
    Last Post: 2nd June 2009, 08:10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.