Results 1 to 7 of 7

Thread: Cannot send data with QTcpSocket

  1. #1
    Join Date
    Nov 2007
    Posts
    24
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Cannot send data with QTcpSocket

    Hi,

    With Qt 4.8 under win32, I'm trying to send data to a tcp server

    Qt Code:
    1.  
    2. sck.connectToHost(myip, 7800);
    3.  
    4. if (sck.waitForConnected(8000)==false)
    5. return -1;
    To copy to clipboard, switch view to plain text mode 

    Connection works pretty well (I see it on the server)
    But now

    Qt Code:
    1. ret = sck.write("test data sending");
    To copy to clipboard, switch view to plain text mode 

    ret returned 17, cool...

    But on server side, I received... nothing !?

    (If I do the same thing in "pure" C socket, it works !?)

    What am I doing wrong ?

    Thanks for you help...
    Last edited by stef13013; 1st September 2012 at 11:23.

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Cannot send data with QTcpSocket

    Qt Code:
    To copy to clipboard, switch view to plain text mode 

    This might be your problem. Does the object live long enough?

  3. The following user says thank you to tbscope for this useful post:

    stef13013 (1st September 2012)

  4. #3
    Join Date
    Nov 2007
    Posts
    24
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Cannot send data with QTcpSocket

    Yes I'm sorry, wrong typo... Anyway problem remains

  5. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Cannot send data with QTcpSocket

    I didn't see the typo. But this isn't what I meant.
    You created the socket on the stack, which means it gets destroyed at the end of the function. Since sockets are asynchronous, the data might not have been sent already at the moment the socket object is destroyed.

  6. #5
    Join Date
    Nov 2007
    Posts
    24
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Cannot send data with QTcpSocket

    Ok, I put it into a class, same problem

    (Even with the debugger I've got the issue)

    Thanks...

  7. #6
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Cannot send data with QTcpSocket

    Try using a network analyzer. This will give you a lot more insight into the actual network traffic.

    I don't know what you mean with "Even with the debugger I've got the issue".

    Edit: Also try to use the error signal to see if there's an error.
    Last edited by tbscope; 1st September 2012 at 11:38.

  8. #7
    Join Date
    Nov 2007
    Posts
    24
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Cannot send data with QTcpSocket

    Thanks for you answer,
    Indeed I wasn't very clear. It was just to say it wasn't an issue with the stack.

    And yes, my last chance is wireshark

Similar Threads

  1. how to use qtcpsocket send qimage data
    By tsuibin in forum Qt Programming
    Replies: 2
    Last Post: 18th April 2012, 14:51
  2. how to send data using QTcpSocket and QTcpServer
    By gauravg in forum Qt Programming
    Replies: 1
    Last Post: 31st March 2012, 12:29
  3. QTcpSocket - try to send bunch of requests
    By nickla in forum Qt Programming
    Replies: 1
    Last Post: 15th March 2012, 20:57
  4. QTcpSocket does not send data immediately
    By igorosberg in forum Qt Programming
    Replies: 11
    Last Post: 15th July 2011, 15:51
  5. How to send Pixmap through QTcpSocket?
    By live_07 in forum Qt Programming
    Replies: 1
    Last Post: 10th September 2008, 16:35

Tags for this Thread

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.