Results 1 to 20 of 58

Thread: Socket Prog

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #34
    Join Date
    Sep 2013
    Posts
    107
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Socket Prog

    Dear All,

    I need to send data to the server, which may have headers, based on the header type. Data will be sent to respective class or lineedit or text edit. But in my client application the entire data is sent across the socket. But, where as in server side I need to check the headers then handle or processs the data.
    Qt Code:
    1. Void Client:: Write()
    2. {
    3. {
    4. QByteArray DATA="001";
    5. QString linedata=ui->lineedit->text();
    6. DATA.append(linedata);
    7. socket.write(DATA.toUf8.constdata());
    8. }
    9. {QByteArray DATA="002";
    10. QString linedata=ui->lineedit_1->text();
    11. DATA.append(linedata);
    12. socket.write(DATA.toUf8.constdata());
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. Void Server::read()
    2. {
    3. {
    4. QTcpSocket *socket = qobject_cast<QTcpSocket*>( sender() );
    5. {
    6. QByteArray buffer= socket->readLine();
    7.  
    8. {
    9. if(buffer.startsWith("001"))
    10. QByteArray buf=buffer;
    11. qDebug()<<buf;
    12. buff=buffer.mid(3)
    13. Lineedit->setText(buff)
    14. qDebug()<<buf;
    15. }
    16. {
    17. if(buffer.startsWith("002"))
    18. QByteArray buf=buffer;
    19. buff=buffer.mid(3)
    20. Lineedit->setText(buff)
    21. }
    To copy to clipboard, switch view to plain text mode 


    Here the problem is when socket is read at server side. In QDebug im getting complete data like "001hello002hi"

    in the Lineedit of server complete line is printed (hello002hi) instead of giving only "hello" and actually by checking with "002" next lineedit_2 as "hi" msg to lineedit_2. How can i address this.
    Last edited by Vivek1982; 25th November 2013 at 11:17. Reason: updated contents

Similar Threads

  1. client/server prog using UDP
    By rajeshakula in forum Newbie
    Replies: 1
    Last Post: 12th July 2011, 11:43
  2. Build issues when qextsrialport.h is included in Linux prog
    By pupqt in forum Installation and Deployment
    Replies: 1
    Last Post: 7th April 2011, 15:48
  3. Replies: 2
    Last Post: 11th March 2010, 09:46
  4. can the image be displayed as it is in chips prog..
    By sh123 in forum Qt Programming
    Replies: 11
    Last Post: 7th February 2009, 08:15
  5. Qt Prog skip the file reading block
    By dgg32 in forum Qt Programming
    Replies: 10
    Last Post: 10th December 2008, 18: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
  •  
Qt is a trademark of The Qt Company.