[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    How to move large data inside a protocol over tcp using Qt/KDE?
From:       "Friedrich W. H. Kossebau" <kossebau () kde ! org>
Date:       2008-09-18 23:24:22
Message-ID: 200809190124.23997.kossebau () kde ! org
[Download RAW message or body]

Hi,

I want to move large data structures over the internet, as part of a custom 
protocol over TCP. Being a newbie on asynchronous i/o over a volatile 
connection I am also a little bit lost how to use Qt/KDE for this. 

The protocol is a custom one, so I thought I just use QDataStream on 
QTCPSocket everywhere. But how will this work if the data doesn't come as 
fast over the network as the other side reads it, so the buffer is underrun? 
(Or is this no problem, does QDataStream just wait? I found no hint to a 
Timeout, which would be nice to have, then). The Qt examples do not seem to 
use QDataStream that way, too.

Using QAbstractSocket::bytesAvailable() does not seem too helpful. Or is there 
a way to ask QDataStream how large the stream will be, so I can pass this in 
front of the next stream/message? Besides, some streams will be very large, 
and it might not be a good idea to fill the buffer with the complete data, 
or?

Instead of using QDataStream I just started to write my own 
AbstractNetworkStreamReader base class, whose subclasses construct the target 
data from blocks of incoming data as it is available:
  public: // API to be implemented
    virtual int nextBytesNeeded() const = 0;
    virtual bool readFrom( QTCPSocket* socket ) = 0;

But now having also to care for things like byte order and best block size I 
wonder if I am really the first one to tackle this problem, sure I am not, 
and if I cannot step on the shoulders of others. 
Do you have any pointers how I do this best, where to look for a template? The 
need to transport large data can happen anytime in the session, and in 
both(!) directions.

Thanks
Friedrich
-- 
Okteta - KDE 4 Hex Editor - http://utils.kde.org/projects/okteta
 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic