Results 1 to 3 of 3

Thread: server-client communication

  1. #1
    Join Date
    Jun 2010
    Posts
    18
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default server-client communication

    - i am new to QT4. Actually i am trying to make a server-client program in which when i send a message from client, it will be displayed in textedit box in server. Once server receives this message, it sends back an acknowledgement sort of message back to client. At client end this message will be displayed in the textedit box.
    - now the problem part. i have been able to send message from client to sever & its being displayed in textedit box at server end. my problem is that when server sends back acknowledgement to client its not being displayed in the textedit box at client end. my code is ...

    client code:
    void client::sendRequest()
    {
    QString msg = msglineEdit->text();
    tcpSocket->write(QString(msg + "\n").toUtf8());
    qDebug() << "Sending to server: " << msg;
    char buffer[1024] = {0};
    tcpSocket->read(buffer, tcpSocket->bytesAvailable());
    qDebug() << "Reading from server: " << buffer;
    responsetextEdit->append( buffer);
    }

    server code:
    void server::startRead()
    {
    char buffer[1024] = {0};
    client->read(buffer, client->bytesAvailable());
    qDebug() << "Reading from client: " << buffer;
    recdtextEdit->append( buffer);
    QString msg = "Received";
    client->write(QString(msg + "\n").toUtf8());
    qDebug() << "Writing to client: " << msg;
    client->close();
    }

    - i dont whats wrong in my code. please help.thanx

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: server-client communication

    1) How do you know when data is available to read? Do you use slot? Is it configured correctly?
    2) Theres no guarantee that the amount of bytes read will be the same as the amount of bytes written

  3. #3
    Join Date
    Jul 2008
    Location
    Philippines
    Posts
    60
    Thanks
    9
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

Similar Threads

  1. tcp QT server - .Net c# client
    By soniaerm in forum Qt Programming
    Replies: 0
    Last Post: 21st April 2010, 22:15
  2. Qt-- Client Server communication problem
    By thisismyuname in forum Qt Programming
    Replies: 2
    Last Post: 8th January 2010, 01:04
  3. Client Server
    By electronicboy in forum General Programming
    Replies: 3
    Last Post: 29th October 2009, 10:10
  4. Replies: 1
    Last Post: 27th March 2009, 13:20

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.