Results 1 to 4 of 4

Thread: tcpscoket problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2008
    Posts
    84
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 1 Time in 1 Post

    Default Re: tcpscoket problem

    sending the data & recieving it is little difficult.
    Can u explain it?

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

    Default Re: tcpscoket problem

    Sending data:
    Assume you already have a socket established.

    Then sending on the socket is just as in the example:
    Qt Code:
    1. QByteArray block;
    2. QDataStream out(&block, QIODevice::WriteOnly);
    3.  
    4. out << QString("test");
    5.  
    6. clientConnection->write(block);
    To copy to clipboard, switch view to plain text mode 

    You need a byte array. You define a Datastream based on the byte array.
    You feed the byte array with data and when finished you just write it to the socket.
    Thats how you send data.

    Receiving data is that you react on the signal bytesAvailable() of the socket.
    You get again a datastream. It is now similar to sending data.

    But for this one it is important to understand that the signal just tells that some data has arrived, not that all data has arrived.
    It is your job to check if everything is already there what you need. That's why in the Fortune example the first thing transmitted is the length of your packet (which I have removed in above example).

    Any futher hint needed?

Similar Threads

  1. Very strange socket programming problem
    By montylee in forum Qt Programming
    Replies: 5
    Last Post: 11th November 2008, 12:05
  2. Problem in using QHttp with QTimer
    By Ferdous in forum Newbie
    Replies: 2
    Last Post: 6th September 2008, 12:48
  3. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 09:12
  4. Steps in solving a programming problem?
    By triperzonak in forum General Programming
    Replies: 8
    Last Post: 5th August 2008, 08:47
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.