Results 1 to 4 of 4

Thread: Client Server

  1. #1
    Join Date
    Oct 2009
    Posts
    30
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Client Server

    hi everybody

    ı am prepairing a client programme which takes data from server.how can ı take data from server.

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Client Server

    Which kind of server do you have?
    A camel can go 14 days without drink,
    I can't!!!

  3. #3
    Join Date
    Oct 2009
    Posts
    30
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Client Server

    Hi again,

    I am writing a socket programme and i send data to my server.

    Qt Code:
    1. bool TcpClient::connectToServer()
    2. {
    3. if(!isConnectionOpen())
    4. {
    5. tcpSocket->connectToHost(_serverAddress,_serverPort);
    6. }
    7. return true;
    8. }
    9.  
    10. QString TcpClient::sendMessageToServer(QString sendMsg)
    11. {
    12. if(!isConnectionOpen())
    13. {
    14. connectToServer();
    15. }
    16. tcpSocket->write((sendMsg+"\n").toAscii().data());
    17. return "OK";
    18. }
    To copy to clipboard, switch view to plain text mode 

    This function is return OK. I want to return response from server. For example;

    My send data : Hello
    Server Response : blablabla
    this function's response : blablabla

    How can I return response from server. I use TCP-IP protocol.

  4. #4
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Client Server

    the better solution is use the signal/slot mechanism connecting the QAbstractSocket::readyRead() signal with one custom slot.

    If you want use a single method that sends and receives data you must use code like:

    Qt Code:
    1. tcpSocket->write((sendMsg+"\n").toAscii().data());
    2. bool ready = false;
    3. while (!ready)
    4. {
    5. // Wait for data received
    6. ready = tcpSocket->waitForReadyRead();
    7. // Check if you can read a line \n terminated
    8. ready &= tcpSocket->canReadLine();
    9. }
    10. QByteArray ba = tcpSocket->readLine();
    11. QString result(ba);
    12. return result;
    To copy to clipboard, switch view to plain text mode 
    A camel can go 14 days without drink,
    I can't!!!

  5. The following user says thank you to mcosta for this useful post:

    electronicboy (30th October 2009)

Similar Threads

  1. Multi Threaded Client Server application
    By live_07 in forum Qt Programming
    Replies: 0
    Last Post: 27th August 2009, 16:32
  2. [PyQt4] SSL server and client example
    By JoelG90 in forum Newbie
    Replies: 1
    Last Post: 24th May 2009, 09:09
  3. Replies: 0
    Last Post: 22nd February 2009, 13:15
  4. Very strange socket programming problem
    By montylee in forum Qt Programming
    Replies: 5
    Last Post: 11th November 2008, 12:05
  5. synching client readings to server output
    By OnionRingOfDoom in forum Qt Programming
    Replies: 14
    Last Post: 28th January 2006, 18:15

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.