Results 1 to 7 of 7

Thread: QTcpServer and QTcpClient

  1. #1
    Join Date
    Dec 2013
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X

    Default QTcpServer and QTcpClient

    Hi,
    for an InterProcessCommunication between a OSX und Linux
    I developed server- and clientprocesses on the Mac with QtCreator.

    The client sends a question to the server. The server solves the problem
    an sends the answer back to the client.
    All works fine!

    But when I starts the two processes outside the QtCreator, nothing works!
    The server and client works correct ( checked with status-messages ),
    but data are'nt swap.

    As a test, i try it with QLocalServer and QLocalSocket. In this case all works fine.
    I can start the applications outside QtCreator and the data will be changed.
    But in the LAN ( OSX and Linux ) this could'nt work.

    Thanks for solutions.

    My english is'nt perfect, so I hope you understand what I wrote!
    Happy Christmas GBunge
    Last edited by GBunge; 24th December 2013 at 15:01.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,403
    Thanks
    37
    Thanked 1,543 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTcpServer and QTcpClient

    There is really not enough information to provide any meaningful help

    Can you verify that the QTcpServer's listen() works? I.e. does it return "true"?
    Are you testing with both on the same machine?

    Cheers,
    _

  3. #3
    Join Date
    Dec 2013
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: QTcpServer and QTcpClient

    Hi,
    first, both tests on the same machine! (Mac)

    Start inside QtCreator all works!

    Start outside:
    The connection is established.
    The server listen returns 'true'.
    If I start the client without running the server, a statusmessage pops up "server not online".

    Make it sense, when I post the code of the two applications?
    And how can I do it?

    GBunge

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,403
    Thanks
    37
    Thanked 1,543 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTcpServer and QTcpClient

    You can attach a ZIP file containing the project.

    Cheers,
    _

  5. #5
    Join Date
    Dec 2013
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: QTcpServer and QTcpClient

    Hi anda_skoa,

    the problem is fixed!
    In the memberfunction 'void IPCServer::readData()'
    Qt Code:
    1. void IPCServer::readData()
    2. { QDataStream in( client );
    3. // Byte-Anzahl auslesen ++++++++++++++++++++++++++
    4. if( anzahl == 0)
    5. { if( client->bytesAvailable() < (int)sizeof(quint16)) return;
    6. in >> anzahl;
    7. }
    8. if( client->bytesAvailable() < anzahl) return;
    9. // Socket auslesen +++++++++++++++++++++++++++++++
    10. in >> data;
    11. // Antwort berechnen +++++++++++++++++++++++++++++
    12. compute( data );
    13. // Antwort senden ++++++++++++++++++++++++++++++++
    14. sendData();
    15. anzahl = 0;
    16. }
    To copy to clipboard, switch view to plain text mode 
    the Classvariable 'anzahl' are not 0.
    Therefor the metode couldn't work.
    I forgot to initialising this variable in the constructor.

    But the mysterium:
    inside QtCreator there is no consequence,
    outside QtCreator the consequence is 'no datatransfer',
    I don't understand this! But it runs!

    Thanks for your time!
    GBunge

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

    Default Re: QTcpServer and QTcpClient

    If you get different behavior in and outside of Creator then it means you are running two different binaries.
    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.


  7. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,403
    Thanks
    37
    Thanked 1,543 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTcpServer and QTcpClient

    If anzahl was not 0 because it was not properly initialized then it might have worked in creator just out of pure luck, i.e. the memory incidentally being 0 in that case.

    Cheers,
    _

  8. The following user says thank you to anda_skoa for this useful post:

    GBunge (26th December 2013)

Similar Threads

  1. QTcpServer
    By DmitryNik in forum Newbie
    Replies: 0
    Last Post: 25th October 2011, 12:36
  2. QTcpServer
    By DmitryNik in forum Newbie
    Replies: 2
    Last Post: 1st October 2011, 08:07
  3. QTcpServer + QThread
    By Alex Snet in forum Qt Programming
    Replies: 2
    Last Post: 14th April 2009, 21:46
  4. QTcpServer and GDB
    By baray98 in forum Qt Programming
    Replies: 2
    Last Post: 21st January 2009, 08:02
  5. Replies: 1
    Last Post: 18th June 2006, 10:12

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.