Results 1 to 6 of 6

Thread: why can't i write some string to the socket

  1. #1

    Default why can't i write some string to the socket

    when i run the code ,it exec correctly
    codes:
    Qt Code:
    1. QBuffer* buffer = new QBuffer(this);
    2. buffer->open(QIODevice::ReadWrite);
    3. qint64 bytes = buffer->write(this->readAll());
    4. buffer->seek(buffer->pos() - bytes);
    5. while (buffer->canReadLine())
    6. {
    7. QByteArray line = buffer->readLine();
    8. write(line);
    9. }
    To copy to clipboard, switch view to plain text mode 
    but when i write("xxxxxxx"),or
    Qt Code:
    1. QString s="xxxxxx"
    2. write(s.toLatin1());
    3. write(s.Ascii());
    4. write(s.toLatin1().data());
    5. ..........................
    To copy to clipboard, switch view to plain text mode 

    i can't write successlly,who can help me
    Last edited by jpn; 2nd December 2008 at 18:24. Reason: missing [code] tags

  2. #2
    Join Date
    Jul 2008
    Posts
    47
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: why can't i write some string to the socket

    Quote Originally Posted by succulent_lily View Post
    qint64 bytes = buffer->write(this->readAll());
    what object is "this->"

  3. #3
    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: why can't i write some string to the socket

    What do you mean you can't write? The application doesn't compile, it returns some error, nothing is sent from the socket or nothing is received on the other side of the connection?

  4. #4

    Default

    Quote Originally Posted by muellerp View Post
    what object is "this->"
    "this->" means the socket

    Quote Originally Posted by wysota View Post
    What do you mean you can't write? The application doesn't compile, it returns some error, nothing is sent from the socket or nothing is received on the other side of the connection?
    thanks for your help
    i wasn't explain the problem complicitly
    this is the server code,the server can receive the client's message which send by socket,and give the message to the client back.
    in my pc,it is run correctly.
    but when the server received the client's message ,i want to send something else string back,such as"xxxxxxx",it can't run.
    that is my problem
    Last edited by wysota; 3rd December 2008 at 09:24.

  5. #5

    Default Re: why can't i write some string to the socket

    Qt Code:
    Qt Code:
    1. QByteArray line2("abcdefg");
    2. QByteArray line = buffer->readLine();
    3. write(line2);
    4. write(buffer->readLine());
    To copy to clipboard, switch view to plain text mode 


    when i run the code ,the client return abcdefg+(the data which go back)
    but if i delete raw 2 and 4,nothing return
    Last edited by jpn; 5th December 2008 at 07:39. Reason: missing [code] tags

  6. #6
    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: why can't i write some string to the socket

    Are you sending a newline or otherwise flushing the socket?

Similar Threads

  1. Reading from sockets in a multithreaded program
    By KoosKoets in forum Qt Programming
    Replies: 9
    Last Post: 4th April 2007, 20:43
  2. saving a c string of variable length in a shared memory?
    By nass in forum General Programming
    Replies: 4
    Last Post: 3rd January 2007, 14:40
  3. How to write on a socket in another thread?
    By Valheru in forum Qt Programming
    Replies: 7
    Last Post: 12th October 2006, 10:52

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.