Results 1 to 3 of 3

Thread: [QTcpServer] read from socket returned by nextPendingConnection

  1. #1
    Join Date
    Jan 2007
    Location
    The Netherlands
    Posts
    15
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default [QTcpServer] read from socket returned by nextPendingConnection

    Hi all,

    I'm having some trouble to read from a QTcpSocket returned by QTcpServer. The situation is like this:

    1) Server listens
    2) Clients connects and sends a message to identify itself
    3) Server creates a Client object using the data in this message

    The problem is #3, a QTcpSocket is returned when calling nextPendingConnection() and the message from the client has been sent correctly. Though the bytesAvailable() function on the returned QTcpSocket keeps returning 0. With as a result that I can't read the message obviously and thus can't create the client object.

    The weird thing is, that when I immediately create a thread to handle the newly returned QTcpSocket I can read from the socket just fine. But since the client object is a thread itself it seems pretty bad to create another thread just to handle the message so I can extract the data.

    Is there anyone who has encountered this before and possibly knows a workaround? I'm willing to post a testcase which probably will illustrate the problem better.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [QTcpServer] read from socket returned by nextPendingConnection

    Quote Originally Posted by saknopper View Post
    Though the bytesAvailable() function on the returned QTcpSocket keeps returning 0.
    Maybe the data hasn't arrived yet? You can use QAbstractSocket::waitForReadyRead() or make the client object process that identification data.

  3. #3
    Join Date
    Jan 2007
    Location
    The Netherlands
    Posts
    15
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: [QTcpServer] read from socket returned by nextPendingConnection

    Processing the message in the client object itself is not really an option at the moment. Since to create such an object I need the data from the message.

    Anyway, if I use waitForReadyRead() it does just nothing, the bytesAvailable() method is called with a little timeout in between of course. It keeps returning 0.

    I've tested it with telnet as well, the connection itself is established properly. bytesAvailable() returns 0 which is ok, since I haven't sent anything. But when I do, it still keeps returning 0. I -can- however write to the socket!

    Like I said, when I instantly create a new thread handling the new QTcpSocket I can read just fine.

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.