| Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date | |
| All threads index page 5 | |
Hi all!! I am sending data across two different processes using a TCP (QTcpSocket) channel and localhost address. Now I am surprised because I have seen on wireshark that TCP (and obviously IP) uses two packets to send 20000 bytes of data. I don't know why TCP uses two packets if communication is in my own PC, Do ip is to blame? My query is: how can I avoid fragmentation with QTcpSocket? I have used "setReadBufferSize(0) = unlimited buffer" but it doesn't work. Any idea? Thanks!!! -- [ signature omitted ]
Setting the read buffer size won't help. You are simply setting the read buffer size of your application, not the size that a tcp packet can handle. I am not an expert, but someone correct me with I am wrong, you would have to change the MTU size to hold the size of data you want. I dont even know if thats feasible. What's the problem with segmentation, tho? You shouldn't bother with it. On Tue, Feb 26, 2008 at 3:17 PM, | pedro mateo || <pedrolmn@xxxxxxxxx> wrote: > Hi all!! > > I am sending data across two different processes using a TCP (QTcpSocket) > channel and localhost address. > Now I am surprised because I have seen on wireshark that TCP (and obviously > IP) uses two packets to send 20000 bytes of data. > I don't know why TCP uses two packets if communication is in my own PC, Do > ip is to blame? > My query is: > how can I avoid fragmentation with QTcpSocket? I have used > "setReadBufferSize(0) = unlimited buffer" but it doesn't work. > Any idea? > > Thanks!!! > > -- > Pedro Luis Mateo Navarro || pedrolmn@xxxxxxxxx _ pedromateo@xxxxxxxxx > > _phone: (+34) 626 14 29 33 or (+34) 968 39 82 58 > > _web: www.pedromana.com > > _msn: pedrolmn@xxxxxxxxxxx -- [ signature omitted ]
On Tuesday 26 February 2008 19:17:40 | pedro mateo || wrote: > I am sending data across two different processes using a TCP (QTcpSocket) > channel and localhost address. > Now I am surprised because I have seen on wireshark that TCP (and obviously > IP) uses two packets to send 20000 bytes of data. > I don't know why TCP uses two packets if communication is in my own PC, Do > ip is to blame? > My query is: > how can I avoid fragmentation with QTcpSocket? I have used > "setReadBufferSize(0) = unlimited buffer" but it doesn't work. > Any idea? This is below QTcpSocket's level. Your operating system decided that it wanted to send the whole thing in one TCP packet, instead of splitting it according to the MTU and sending serially. -- [ signature omitted ]
Attachment:
signature.asc
Description: This is a digitally signed message part.
First, thanks!! I think MTU shouldn't be the reason of my trouble because Routers uses it to split data when it is necessary, but my data is always on my computer, I don't use my LAN to send something. Cheers!!! On Tue, Feb 26, 2008 at 7:34 PM, Thiago Macieira < thiago.macieira@xxxxxxxxxxxxx> wrote: > On Tuesday 26 February 2008 19:17:40 | pedro mateo || wrote: > > I am sending data across two different processes using a TCP > (QTcpSocket) > > channel and localhost address. > > Now I am surprised because I have seen on wireshark that TCP (and > obviously > > IP) uses two packets to send 20000 bytes of data. > > I don't know why TCP uses two packets if communication is in my own PC, > Do > > ip is to blame? > > My query is: > > how can I avoid fragmentation with QTcpSocket? I have used > > "setReadBufferSize(0) = unlimited buffer" but it doesn't work. > > Any idea? > > This is below QTcpSocket's level. Your operating system decided that it > wanted > to send the whole thing in one TCP packet, instead of splitting it > according > to the MTU and sending serially. > > -- > Thiago José Macieira - thiago.macieira AT trolltech.com > Trolltech ASA - Sandakerveien 116, NO-0402 Oslo, Norway > -- [ signature omitted ]
On Tue, Feb 26, 2008 at 3:42 PM, | pedro mateo || <pedrolmn@xxxxxxxxx> wrote: > First, thanks!! > > I think MTU shouldn't be the reason of my trouble because Routers uses it to > split data when it is necessary, but my data is always on my computer, I > don't use my LAN to send something. Yet, you are probably using the loopback interface, which relies on tcp packets. So MTU does matter. But just for curiosity, whats the problem with segmentation? > > Cheers!!! > > > > On Tue, Feb 26, 2008 at 7:34 PM, Thiago Macieira > <thiago.macieira@xxxxxxxxxxxxx> wrote: > > > > On Tuesday 26 February 2008 19:17:40 | pedro mateo || wrote: > > > I am sending data across two different processes using a TCP > (QTcpSocket) > > > channel and localhost address. > > > Now I am surprised because I have seen on wireshark that TCP (and > obviously > > > IP) uses two packets to send 20000 bytes of data. > > > I don't know why TCP uses two packets if communication is in my own PC, > Do > > > ip is to blame? > > > My query is: > > > how can I avoid fragmentation with QTcpSocket? I have used > > > "setReadBufferSize(0) = unlimited buffer" but it doesn't work. > > > Any idea? > > > > This is below QTcpSocket's level. Your operating system decided that it > wanted > > to send the whole thing in one TCP packet, instead of splitting it > according > > to the MTU and sending serially. > > > > -- > > Thiago José Macieira - thiago.macieira AT trolltech.com > > Trolltech ASA - Sandakerveien 116, NO-0402 Oslo, Norway > > > > > > > -- > Pedro Luis Mateo Navarro || pedrolmn@xxxxxxxxx _ pedromateo@xxxxxxxxx > > _phone: (+34) 626 14 29 33 or (+34) 968 39 82 58 > > _web: www.pedromana.com > > _msn: pedrolmn@xxxxxxxxxxx -- [ signature omitted ]
Hi!! On Tue, Feb 26, 2008 at 7:49 PM, Rafael Roquetto <rafaelroquetto@xxxxxxxxx> wrote: > On Tue, Feb 26, 2008 at 3:42 PM, | pedro mateo || <pedrolmn@xxxxxxxxx> > wrote: > > First, thanks!! > > > > I think MTU shouldn't be the reason of my trouble because Routers uses > it to > > split data when it is necessary, but my data is always on my computer, I > > don't use my LAN to send something. > Yet, you are probably using the loopback interface, which relies on > tcp packets. So MTU does matter. > > But just for curiosity, whats the problem with segmentation? I'm using TCP to send xml data. When a new TCP packet arrives, socket emits Readyread signal and I get all the text I need. If XML text is fragmented in two packets, I will receive two readyread signals, therefore I will receive two different XML strings, each one a half of the original XML string. I need to get only one XML string like the original (1 xml string = 1 event). When I receive the first readyread signal, I could wait for the second one, but I can't be sure if the new received data belongs to the last TCP packet, it may be a new TCP packet. cheers!! > > > > > > Cheers!!! > > > > > > > > On Tue, Feb 26, 2008 at 7:34 PM, Thiago Macieira > > <thiago.macieira@xxxxxxxxxxxxx> wrote: > > > > > > On Tuesday 26 February 2008 19:17:40 | pedro mateo || wrote: > > > > I am sending data across two different processes using a TCP > > (QTcpSocket) > > > > channel and localhost address. > > > > Now I am surprised because I have seen on wireshark that TCP (and > > obviously > > > > IP) uses two packets to send 20000 bytes of data. > > > > I don't know why TCP uses two packets if communication is in my own > PC, > > Do > > > > ip is to blame? > > > > My query is: > > > > how can I avoid fragmentation with QTcpSocket? I have used > > > > "setReadBufferSize(0) = unlimited buffer" but it doesn't work. > > > > Any idea? > > > > > > This is below QTcpSocket's level. Your operating system decided that > it > > wanted > > > to send the whole thing in one TCP packet, instead of splitting it > > according > > > to the MTU and sending serially. > > > > > > -- > > > Thiago José Macieira - thiago.macieira AT trolltech.com > > > Trolltech ASA - Sandakerveien 116, NO-0402 Oslo, Norway > > > > > > > > > > > > > -- > > Pedro Luis Mateo Navarro || pedrolmn@xxxxxxxxx _ pedromateo@xxxxxxxxx > > > _phone: (+34) 626 14 29 33 or (+34) 968 39 82 58 > > > _web: www.pedromana.com > > > _msn: pedrolmn@xxxxxxxxxxx > -- [ signature omitted ]
On Tuesday 26 February 2008 21:46:53 | pedro mateo || wrote: > I'm using TCP to send xml data. > When a new TCP packet arrives, socket emits Readyread signal and I get all > the text I need. > If XML text is fragmented in two packets, I will receive two readyread > signals, therefore I will receive two different XML strings, each one a > half of the original XML string. > I need to get only one XML string like the original (1 xml string = 1 > event). > > When I receive the first readyread signal, I could wait for the second one, > but I can't be sure if the new received data belongs to the last TCP > packet, it may be a new TCP packet. I suppose you're using some kind of SAX parser. Why don't you then feed XML parts to it? It should be capable of parsing partial XML (if I remember it correctly from QtXml docs). To distinguish one message from another you have just to enclose your event in one xml tag, pretty much like XMPP <message> behave. e.g. you can get part of a <message>, several <message>'s (if server decides to send several small messages in one packet), etc. Still your exact message is inside <message>...</message> so you can handle it. -- [ signature omitted ]
Attachment:
signature.asc
Description: This is a digitally signed message part.
| pedro mateo || wrote: >When I receive the first readyread signal, I could wait for the second > one, but I can't be sure if the new received data belongs to the last > TCP packet, it may be a new TCP packet. That's how TCP works. It might be broken up to different chunks whether you want it or not. Your code must cope with the fact that not everything may have been received. -- [ signature omitted ]
Attachment:
signature.asc
Description: This is a digitally signed message part.
As Thiago said, that is how TCP works. I suggest you use QXmlStreamReader to parse data from socket. You can use QXmlStreamReader::setDevice() and pass a socket fd to it. Then, whenever data arrives, it tries to parse. If the xml is not complete, the parser will return a premature end of document, keeping its state. This is what you should do, IMHO. | pedro mateo || wrote: > Hi!! > > On Tue, Feb 26, 2008 at 7:49 PM, Rafael Roquetto > <rafaelroquetto@xxxxxxxxx <mailto:rafaelroquetto@xxxxxxxxx>> wrote: > > On Tue, Feb 26, 2008 at 3:42 PM, | pedro mateo || > <pedrolmn@xxxxxxxxx <mailto:pedrolmn@xxxxxxxxx>> wrote: > > First, thanks!! > > > > I think MTU shouldn't be the reason of my trouble because > Routers uses it to > > split data when it is necessary, but my data is always on my > computer, I > > don't use my LAN to send something. > Yet, you are probably using the loopback interface, which relies on > tcp packets. So MTU does matter. > > But just for curiosity, whats the problem with segmentation? > > > I'm using TCP to send xml data. > When a new TCP packet arrives, socket emits Readyread signal and I get > all the text I need. > If XML text is fragmented in two packets, I will receive two readyread > signals, therefore I will receive two different XML strings, each one > a half of the original XML string. > I need to get only one XML string like the original (1 xml string = 1 > event). > > When I receive the first readyread signal, I could wait for the second > one, but I can't be sure if the new received data belongs to the last > TCP packet, it may be a new TCP packet. > > cheers!! > > > > > > > > Cheers!!! > > > > > > > > On Tue, Feb 26, 2008 at 7:34 PM, Thiago Macieira > > <thiago.macieira@xxxxxxxxxxxxx > <mailto:thiago.macieira@xxxxxxxxxxxxx>> wrote: > > > > > > On Tuesday 26 February 2008 19:17:40 | pedro mateo || wrote: > > > > I am sending data across two different processes using a TCP > > (QTcpSocket) > > > > channel and localhost address. > > > > Now I am surprised because I have seen on wireshark that TCP > (and > > obviously > > > > IP) uses two packets to send 20000 bytes of data. > > > > I don't know why TCP uses two packets if communication is in > my own PC, > > Do > > > > ip is to blame? > > > > My query is: > > > > how can I avoid fragmentation with QTcpSocket? I have used > > > > "setReadBufferSize(0) = unlimited buffer" but it doesn't work. > > > > Any idea? > > > > > > This is below QTcpSocket's level. Your operating system > decided that it > > wanted > > > to send the whole thing in one TCP packet, instead of splitting it > > according > > > to the MTU and sending serially. > > > > > > -- > > > Thiago José Macieira - thiago.macieira AT trolltech.com > <http://trolltech.com> > > > Trolltech ASA - Sandakerveien 116, NO-0402 Oslo, Norway > > > > > > > > > > > > > -- > > Pedro Luis Mateo Navarro || pedrolmn@xxxxxxxxx > <mailto:pedrolmn@xxxxxxxxx> _ pedromateo@xxxxxxxxx > <mailto:pedromateo@xxxxxxxxx> > > > _phone: (+34) 626 14 29 33 or (+34) 968 39 82 58 > > > _web: www.pedromana.com <http://www.pedromana.com> > > > _msn: pedrolmn@xxxxxxxxxxx <mailto:pedrolmn@xxxxxxxxxxx> > > > > > -- > Pedro Luis Mateo Navarro || pedrolmn@xxxxxxxxx > <mailto:pedrolmn@xxxxxxxxx> _ pedromateo@xxxxxxxxx > <mailto:pedromateo@xxxxxxxxx> > > _phone: (+34) 626 14 29 33 or (+34) 968 39 82 58 > > _web: www.pedromana.com <http://www.pedromana.com> > > _msn: pedrolmn@xxxxxxxxxxx <mailto:pedrolmn@xxxxxxxxxxx> -- [ signature omitted ]
On onsdag den 27. Februar 2008, Rafael Roquetto wrote: > As Thiago said, that is how TCP works. > > I suggest you use QXmlStreamReader to parse data from socket. You can > use QXmlStreamReader::setDevice() and pass a socket fd to it. > Then, whenever data arrives, it tries to parse. If the xml is not > complete, the parser will return a premature end of document, keeping > its state. > This is what you should do, IMHO. Another solution is to do a simple extension. Instead of sending just the XML file, send first a single line with the number of bytes in the XML file. Then it's easy to wait until the entire amount of data is available before actually reading it. Planning for split packages also makes it a lot easier to later take the application to do network communication on more than one machine. If you don't get this right from the beginning, you're going to have debugging hell. At first, I thought this problem was that the OP was concerned about speed. But since he's using XML for the communications, I guess the network speed is irrelevant. Bo. > | pedro mateo || wrote: > | > > Hi!! > > > > On Tue, Feb 26, 2008 at 7:49 PM, Rafael Roquetto > > <rafaelroquetto@xxxxxxxxx <mailto:rafaelroquetto@xxxxxxxxx>> wrote: > > > > On Tue, Feb 26, 2008 at 3:42 PM, | pedro mateo || > > > > <pedrolmn@xxxxxxxxx <mailto:pedrolmn@xxxxxxxxx>> wrote: > > > First, thanks!! > > > > > > I think MTU shouldn't be the reason of my trouble because > > > > Routers uses it to > > > > > split data when it is necessary, but my data is always on my > > > > computer, I > > > > > don't use my LAN to send something. > > > > Yet, you are probably using the loopback interface, which relies on > > tcp packets. So MTU does matter. > > > > But just for curiosity, whats the problem with segmentation? > > > > > > I'm using TCP to send xml data. > > When a new TCP packet arrives, socket emits Readyread signal and I get > > all the text I need. > > If XML text is fragmented in two packets, I will receive two readyread > > signals, therefore I will receive two different XML strings, each one > > a half of the original XML string. > > I need to get only one XML string like the original (1 xml string = 1 > > event). > > > > When I receive the first readyread signal, I could wait for the second > > one, but I can't be sure if the new received data belongs to the last > > TCP packet, it may be a new TCP packet. > > > > cheers!! > > > > > Cheers!!! > > > > > > > > > > > > On Tue, Feb 26, 2008 at 7:34 PM, Thiago Macieira > > > <thiago.macieira@xxxxxxxxxxxxx > > > > <mailto:thiago.macieira@xxxxxxxxxxxxx>> wrote: > > > > On Tuesday 26 February 2008 19:17:40 | pedro mateo || wrote: > > > > > I am sending data across two different processes using a TCP > > > > > > (QTcpSocket) > > > > > > > > channel and localhost address. > > > > > Now I am surprised because I have seen on wireshark that TCP > > > > (and > > > > > obviously > > > > > > > > IP) uses two packets to send 20000 bytes of data. > > > > > I don't know why TCP uses two packets if communication is in > > > > my own PC, > > > > > Do > > > > > > > > ip is to blame? > > > > > My query is: > > > > > how can I avoid fragmentation with QTcpSocket? I have used > > > > > "setReadBufferSize(0) = unlimited buffer" but it doesn't work. > > > > > Any idea? > > > > > > > > This is below QTcpSocket's level. Your operating system > > > > decided that it > > > > > wanted > > > > > > > to send the whole thing in one TCP packet, instead of splitting > > > > it > > > > > > according > > > > > > > to the MTU and sending serially. > > > > > > > > -- > > > > Thiago José Macieira - thiago.macieira AT trolltech.com > > > > <http://trolltech.com> > > > > > > Trolltech ASA - Sandakerveien 116, NO-0402 Oslo, Norway > > > > > > -- > > > Pedro Luis Mateo Navarro || pedrolmn@xxxxxxxxx > > > > <mailto:pedrolmn@xxxxxxxxx> _ pedromateo@xxxxxxxxx > > <mailto:pedromateo@xxxxxxxxx> > > > > > > _phone: (+34) 626 14 29 33 or (+34) 968 39 82 58 > > > > _web: www.pedromana.com <http://www.pedromana.com> > > > > _msn: pedrolmn@xxxxxxxxxxx <mailto:pedrolmn@xxxxxxxxxxx> > > > > -- > > Pedro Luis Mateo Navarro || pedrolmn@xxxxxxxxx > > <mailto:pedrolmn@xxxxxxxxx> _ pedromateo@xxxxxxxxx > > <mailto:pedromateo@xxxxxxxxx> > > > > > _phone: (+34) 626 14 29 33 or (+34) 968 39 82 58 > > > _web: www.pedromana.com <http://www.pedromana.com> > > > _msn: pedrolmn@xxxxxxxxxxx <mailto:pedrolmn@xxxxxxxxxxx> > > -- > To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with > "unsubscribe" in the subject or the body. List archive and information: > http://lists.trolltech.com/qt-interest/ -- [ signature omitted ]
Pedro, here is what I did when I needed to parse XML data coming across
network, in a toll road system:
I have this class, called Lane, which has a socket attribute and a
socketReady() slot. The first thing I did was connecting socketReady()
slot to the socket's readyRead() signal, as in
connect(socket, SIGNAL(readyRead()),
this, SLOT(socketReady()));
This Lane class also has a parser attribute of the type Parser. Parser
is a class I implemented descending from QObject, and it takes a
reference to a QXmlStreamReader on its constructor. It has a method
called Parser::parse(), implemented as follows:
void Parser::parse()
{
QXmlStreamReader::TokenType tokenType;
QStringRef name;
while(!xml.atEnd())
{
tokenType = xml.readNext();
name = xml.name();
if(tokenType == QXmlStreamReader::StartElement)
{
if(name == "stream")
handleStream();
else if(name == "message")
currentHandler = MESSAGE;
}
else if(tokenType == QXmlStreamReader::Characters)
{
if(currentHandler == MESSAGE)
handleMessage();
}
else if(tokenType == QXmlStreamReader::EndElement)
{
if(currentHandler == MESSAGE)
currentHandler = DEFAULT;
}
}
if(xml.hasError())
logger.debug(xml.errorString());
}
This method tried to parse the XML present on QXmlStreamReader. Note
that the while loop condition is "!xml.atEnd()". It will abort in case
the XML document is yet incomplete (i.e. only a chunk of data has
arrived to feed QXmlStreamReader), however, it will save its state and
you will be able to proceed once more data has been fed to QXmlStreamReader.
How is that fed?
In my Lane class, I also create an instance of QXmlStreamReader, and
calls xmlStreamReader.setDevice(socket);
This will feed QXmlStreamReader with data coming from the socket.
Remember that I also connected socket's readyRead() to socketReady()
slot? So, when socketReady() signal is called, I know data has arrived
at the socket, and that it has already been fed to my xmlStreamReader.
So inside socketReady() signal I simply call parser.parse().
This is basically it. You should try some approach like this for
yourself. It is like math, if you never try it yourself, you will never
learn. I don't know if I was able to really convey what I mean, I am not
a very good writer, you know.
Refer on Google to "Incremental Xml Parsing". This will give you more
background on how QXmlStreamReader works.
Rafael
Bo Thorsen wrote:
> On onsdag den 27. Februar 2008, Rafael Roquetto wrote:
>
>> As Thiago said, that is how TCP works.
>>
>> I suggest you use QXmlStreamReader to parse data from socket. You can
>> use QXmlStreamReader::setDevice() and pass a socket fd to it.
>> Then, whenever data arrives, it tries to parse. If the xml is not
>> complete, the parser will return a premature end of document, keeping
>> its state.
>> This is what you should do, IMHO.
>>
>
> Another solution is to do a simple extension. Instead of sending just the XML
> file, send first a single line with the number of bytes in the XML file. Then
> it's easy to wait until the entire amount of data is available before
> actually reading it.
>
> Planning for split packages also makes it a lot easier to later take the
> application to do network communication on more than one machine. If you
> don't get this right from the beginning, you're going to have debugging hell.
>
> At first, I thought this problem was that the OP was concerned about speed.
> But since he's using XML for the communications, I guess the network speed is
> irrelevant.
>
> Bo.
>
>
>> | pedro mateo || wrote:
>> |
>>
>>> Hi!!
>>>
>>> On Tue, Feb 26, 2008 at 7:49 PM, Rafael Roquetto
>>> <rafaelroquetto@xxxxxxxxx <mailto:rafaelroquetto@xxxxxxxxx>> wrote:
>>>
>>> On Tue, Feb 26, 2008 at 3:42 PM, | pedro mateo ||
>>>
>>> <pedrolmn@xxxxxxxxx <mailto:pedrolmn@xxxxxxxxx>> wrote:
>>> > First, thanks!!
>>> >
>>> > I think MTU shouldn't be the reason of my trouble because
>>>
>>> Routers uses it to
>>>
>>> > split data when it is necessary, but my data is always on my
>>>
>>> computer, I
>>>
>>> > don't use my LAN to send something.
>>>
>>> Yet, you are probably using the loopback interface, which relies on
>>> tcp packets. So MTU does matter.
>>>
>>> But just for curiosity, whats the problem with segmentation?
>>>
>>>
>>> I'm using TCP to send xml data.
>>> When a new TCP packet arrives, socket emits Readyread signal and I get
>>> all the text I need.
>>> If XML text is fragmented in two packets, I will receive two readyread
>>> signals, therefore I will receive two different XML strings, each one
>>> a half of the original XML string.
>>> I need to get only one XML string like the original (1 xml string = 1
>>> event).
>>>
>>> When I receive the first readyread signal, I could wait for the second
>>> one, but I can't be sure if the new received data belongs to the last
>>> TCP packet, it may be a new TCP packet.
>>>
>>> cheers!!
>>>
>>> > Cheers!!!
>>> >
>>> >
>>> >
>>> > On Tue, Feb 26, 2008 at 7:34 PM, Thiago Macieira
>>> > <thiago.macieira@xxxxxxxxxxxxx
>>>
>>> <mailto:thiago.macieira@xxxxxxxxxxxxx>> wrote:
>>> > > On Tuesday 26 February 2008 19:17:40 | pedro mateo || wrote:
>>> > > > I am sending data across two different processes using a TCP
>>> >
>>> > (QTcpSocket)
>>> >
>>> > > > channel and localhost address.
>>> > > > Now I am surprised because I have seen on wireshark that TCP
>>>
>>> (and
>>>
>>> > obviously
>>> >
>>> > > > IP) uses two packets to send 20000 bytes of data.
>>> > > > I don't know why TCP uses two packets if communication is in
>>>
>>> my own PC,
>>>
>>> > Do
>>> >
>>> > > > ip is to blame?
>>> > > > My query is:
>>> > > > how can I avoid fragmentation with QTcpSocket? I have used
>>> > > > "setReadBufferSize(0) = unlimited buffer" but it doesn't work.
>>> > > > Any idea?
>>> > >
>>> > > This is below QTcpSocket's level. Your operating system
>>>
>>> decided that it
>>>
>>> > wanted
>>> >
>>> > > to send the whole thing in one TCP packet, instead of splitting
>>> > > it
>>> >
>>> > according
>>> >
>>> > > to the MTU and sending serially.
>>> > >
>>> > > --
>>> > > Thiago José Macieira - thiago.macieira AT trolltech.com
>>>
>>> <http://trolltech.com>
>>>
>>> > > Trolltech ASA - Sandakerveien 116, NO-0402 Oslo, Norway
>>> >
>>> > --
>>> > Pedro Luis Mateo Navarro || pedrolmn@xxxxxxxxx
>>>
>>> <mailto:pedrolmn@xxxxxxxxx> _ pedromateo@xxxxxxxxx
>>> <mailto:pedromateo@xxxxxxxxx>
>>>
>>> > > _phone: (+34) 626 14 29 33 or (+34) 968 39 82 58
>>> > > _web: www.pedromana.com <http://www.pedromana.com>
>>> > > _msn: pedrolmn@xxxxxxxxxxx <mailto:pedrolmn@xxxxxxxxxxx>
>>>
>>> --
>>> Pedro Luis Mateo Navarro || pedrolmn@xxxxxxxxx
>>> <mailto:pedrolmn@xxxxxxxxx> _ pedromateo@xxxxxxxxx
>>> <mailto:pedromateo@xxxxxxxxx>
>>>
>>> > _phone: (+34) 626 14 29 33 or (+34) 968 39 82 58
>>> > _web: www.pedromana.com <http://www.pedromana.com>
>>> > _msn: pedrolmn@xxxxxxxxxxx <mailto:pedrolmn@xxxxxxxxxxx>
>>>
>> --
>> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
>> "unsubscribe" in the subject or the body. List archive and information:
>> http://lists.trolltech.com/qt-interest/
>>
>
>
>
>
--
[ signature omitted ]
Thanks to all!!
Finally, I have solved my trouble in an "upper layer".
If XMLControl (wich uses QTcpSocket) receives a xml string without the
</close-tag>, it stores the string. When it receives this tag, it manages
it.
I think that is the simplest solution, despite I wanted to manage that
trouble at the socket-level at first.
Cheers!!
PS: sorry my english, I really have to improve it. ;-P
On Wed, Feb 27, 2008 at 12:24 PM, Rafael Roquetto <rafaelroquetto@xxxxxxxxx>
wrote:
> Pedro, here is what I did when I needed to parse XML data coming across
> network, in a toll road system:
>
> I have this class, called Lane, which has a socket attribute and a
> socketReady() slot. The first thing I did was connecting socketReady()
> slot to the socket's readyRead() signal, as in
>
> connect(socket, SIGNAL(readyRead()),
> this, SLOT(socketReady()));
>
> This Lane class also has a parser attribute of the type Parser. Parser
> is a class I implemented descending from QObject, and it takes a
> reference to a QXmlStreamReader on its constructor. It has a method
> called Parser::parse(), implemented as follows:
>
>
> void Parser::parse()
> {
> QXmlStreamReader::TokenType tokenType;
> QStringRef name;
>
> while(!xml.atEnd())
> {
> tokenType = xml.readNext();
>
> name = xml.name();
>
> if(tokenType == QXmlStreamReader::StartElement)
> {
> if(name == "stream")
> handleStream();
> else if(name == "message")
> currentHandler = MESSAGE;
> }
> else if(tokenType == QXmlStreamReader::Characters)
> {
> if(currentHandler == MESSAGE)
> handleMessage();
> }
> else if(tokenType == QXmlStreamReader::EndElement)
> {
> if(currentHandler == MESSAGE)
> currentHandler = DEFAULT;
> }
> }
>
> if(xml.hasError())
> logger.debug(xml.errorString());
> }
>
> This method tried to parse the XML present on QXmlStreamReader. Note
> that the while loop condition is "!xml.atEnd()". It will abort in case
> the XML document is yet incomplete (i.e. only a chunk of data has
> arrived to feed QXmlStreamReader), however, it will save its state and
> you will be able to proceed once more data has been fed to
> QXmlStreamReader.
>
> How is that fed?
>
> In my Lane class, I also create an instance of QXmlStreamReader, and
> calls xmlStreamReader.setDevice(socket);
> This will feed QXmlStreamReader with data coming from the socket.
> Remember that I also connected socket's readyRead() to socketReady()
> slot? So, when socketReady() signal is called, I know data has arrived
> at the socket, and that it has already been fed to my xmlStreamReader.
> So inside socketReady() signal I simply call parser.parse().
>
> This is basically it. You should try some approach like this for
> yourself. It is like math, if you never try it yourself, you will never
> learn. I don't know if I was able to really convey what I mean, I am not
> a very good writer, you know.
>
> Refer on Google to "Incremental Xml Parsing". This will give you more
> background on how QXmlStreamReader works.
>
> Rafael
>
>
> Bo Thorsen wrote:
> > On onsdag den 27. Februar 2008, Rafael Roquetto wrote:
> >
> >> As Thiago said, that is how TCP works.
> >>
> >> I suggest you use QXmlStreamReader to parse data from socket. You can
> >> use QXmlStreamReader::setDevice() and pass a socket fd to it.
> >> Then, whenever data arrives, it tries to parse. If the xml is not
> >> complete, the parser will return a premature end of document, keeping
> >> its state.
> >> This is what you should do, IMHO.
> >>
> >
> > Another solution is to do a simple extension. Instead of sending just
> the XML
> > file, send first a single line with the number of bytes in the XML file.
> Then
> > it's easy to wait until the entire amount of data is available before
> > actually reading it.
> >
> > Planning for split packages also makes it a lot easier to later take the
> > application to do network communication on more than one machine. If you
> > don't get this right from the beginning, you're going to have debugging
> hell.
> >
> > At first, I thought this problem was that the OP was concerned about
> speed.
> > But since he's using XML for the communications, I guess the network
> speed is
> > irrelevant.
> >
> > Bo.
> >
> >
> >> | pedro mateo || wrote:
> >> |
> >>
> >>> Hi!!
> >>>
> >>> On Tue, Feb 26, 2008 at 7:49 PM, Rafael Roquetto
> >>> <rafaelroquetto@xxxxxxxxx <mailto:rafaelroquetto@xxxxxxxxx>> wrote:
> >>>
> >>> On Tue, Feb 26, 2008 at 3:42 PM, | pedro mateo ||
> >>>
> >>> <pedrolmn@xxxxxxxxx <mailto:pedrolmn@xxxxxxxxx>> wrote:
> >>> > First, thanks!!
> >>> >
> >>> > I think MTU shouldn't be the reason of my trouble because
> >>>
> >>> Routers uses it to
> >>>
> >>> > split data when it is necessary, but my data is always on my
> >>>
> >>> computer, I
> >>>
> >>> > don't use my LAN to send something.
> >>>
> >>> Yet, you are probably using the loopback interface, which relies
> on
> >>> tcp packets. So MTU does matter.
> >>>
> >>> But just for curiosity, whats the problem with segmentation?
> >>>
> >>>
> >>> I'm using TCP to send xml data.
> >>> When a new TCP packet arrives, socket emits Readyread signal and I get
> >>> all the text I need.
> >>> If XML text is fragmented in two packets, I will receive two readyread
> >>> signals, therefore I will receive two different XML strings, each one
> >>> a half of the original XML string.
> >>> I need to get only one XML string like the original (1 xml string = 1
> >>> event).
> >>>
> >>> When I receive the first readyread signal, I could wait for the second
> >>> one, but I can't be sure if the new received data belongs to the last
> >>> TCP packet, it may be a new TCP packet.
> >>>
> >>> cheers!!
> >>>
> >>> > Cheers!!!
> >>> >
> >>> >
> >>> >
> >>> > On Tue, Feb 26, 2008 at 7:34 PM, Thiago Macieira
> >>> > <thiago.macieira@xxxxxxxxxxxxx
> >>>
> >>> <mailto:thiago.macieira@xxxxxxxxxxxxx>> wrote:
> >>> > > On Tuesday 26 February 2008 19:17:40 | pedro mateo || wrote:
> >>> > > > I am sending data across two different processes using a TCP
> >>> >
> >>> > (QTcpSocket)
> >>> >
> >>> > > > channel and localhost address.
> >>> > > > Now I am surprised because I have seen on wireshark that TCP
> >>>
> >>> (and
> >>>
> >>> > obviously
> >>> >
> >>> > > > IP) uses two packets to send 20000 bytes of data.
> >>> > > > I don't know why TCP uses two packets if communication is in
> >>>
> >>> my own PC,
> >>>
> >>> > Do
> >>> >
> >>> > > > ip is to blame?
> >>> > > > My query is:
> >>> > > > how can I avoid fragmentation with QTcpSocket? I have used
> >>> > > > "setReadBufferSize(0) = unlimited buffer" but it doesn't
> work.
> >>> > > > Any idea?
> >>> > >
> >>> > > This is below QTcpSocket's level. Your operating system
> >>>
> >>> decided that it
> >>>
> >>> > wanted
> >>> >
> >>> > > to send the whole thing in one TCP packet, instead of
> splitting
> >>> > > it
> >>> >
> >>> > according
> >>> >
> >>> > > to the MTU and sending serially.
> >>> > >
> >>> > > --
> >>> > > Thiago José Macieira - thiago.macieira AT trolltech.com
> >>>
> >>> <http://trolltech.com>
> >>>
> >>> > > Trolltech ASA - Sandakerveien 116, NO-0402 Oslo, Norway
> >>> >
> >>> > --
> >>> > Pedro Luis Mateo Navarro || pedrolmn@xxxxxxxxx
> >>>
> >>> <mailto:pedrolmn@xxxxxxxxx> _ pedromateo@xxxxxxxxx
> >>> <mailto:pedromateo@xxxxxxxxx>
> >>>
> >>> > > _phone: (+34) 626 14 29 33 or (+34) 968 39 82 58
> >>> > > _web: www.pedromana.com <http://www.pedromana.com>
> >>> > > _msn: pedrolmn@xxxxxxxxxxx <mailto:pedrolmn@xxxxxxxxxxx>
> >>>
> >>> --
> >>> Pedro Luis Mateo Navarro || pedrolmn@xxxxxxxxx
> >>> <mailto:pedrolmn@xxxxxxxxx> _ pedromateo@xxxxxxxxx
> >>> <mailto:pedromateo@xxxxxxxxx>
> >>>
> >>> > _phone: (+34) 626 14 29 33 or (+34) 968 39 82 58
> >>> > _web: www.pedromana.com <http://www.pedromana.com>
> >>> > _msn: pedrolmn@xxxxxxxxxxx <mailto:pedrolmn@xxxxxxxxxxx>
> >>>
> >> --
> >> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> >> "unsubscribe" in the subject or the body. List archive and information:
> >> http://lists.trolltech.com/qt-interest/
> >>
> >
> >
> >
> >
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
--
[ signature omitted ]
What happens if it receives
<clos
in one chuck of data
and
e-tag/> in another?
On Wed, Feb 27, 2008 at 2:43 PM, | pedro mateo || <pedrolmn@xxxxxxxxx> wrote:
> Thanks to all!!
>
> Finally, I have solved my trouble in an "upper layer".
> If XMLControl (wich uses QTcpSocket) receives a xml string without the
> </close-tag>, it stores the string. When it receives this tag, it manages
> it.
>
> I think that is the simplest solution, despite I wanted to manage that
> trouble at the socket-level at first.
>
> Cheers!!
>
> PS: sorry my english, I really have to improve it. ;-P
>
>
>
> On Wed, Feb 27, 2008 at 12:24 PM, Rafael Roquetto
> <rafaelroquetto@xxxxxxxxx> wrote:
> > Pedro, here is what I did when I needed to parse XML data coming across
> > network, in a toll road system:
> >
> > I have this class, called Lane, which has a socket attribute and a
> > socketReady() slot. The first thing I did was connecting socketReady()
> > slot to the socket's readyRead() signal, as in
> >
> > connect(socket, SIGNAL(readyRead()),
> > this, SLOT(socketReady()));
> >
> > This Lane class also has a parser attribute of the type Parser. Parser
> > is a class I implemented descending from QObject, and it takes a
> > reference to a QXmlStreamReader on its constructor. It has a method
> > called Parser::parse(), implemented as follows:
> >
> >
> > void Parser::parse()
> > {
> > QXmlStreamReader::TokenType tokenType;
> > QStringRef name;
> >
> > while(!xml.atEnd())
> > {
> > tokenType = xml.readNext();
> >
> > name = xml.name();
> >
> > if(tokenType == QXmlStreamReader::StartElement)
> > {
> > if(name == "stream")
> > handleStream();
> > else if(name == "message")
> > currentHandler = MESSAGE;
> > }
> > else if(tokenType == QXmlStreamReader::Characters)
> > {
> > if(currentHandler == MESSAGE)
> > handleMessage();
> > }
> > else if(tokenType == QXmlStreamReader::EndElement)
> > {
> > if(currentHandler == MESSAGE)
> > currentHandler = DEFAULT;
> > }
> > }
> >
> > if(xml.hasError())
> > logger.debug(xml.errorString());
> > }
> >
> > This method tried to parse the XML present on QXmlStreamReader. Note
> > that the while loop condition is "!xml.atEnd()". It will abort in case
> > the XML document is yet incomplete (i.e. only a chunk of data has
> > arrived to feed QXmlStreamReader), however, it will save its state and
> > you will be able to proceed once more data has been fed to
> QXmlStreamReader.
> >
> > How is that fed?
> >
> > In my Lane class, I also create an instance of QXmlStreamReader, and
> > calls xmlStreamReader.setDevice(socket);
> > This will feed QXmlStreamReader with data coming from the socket.
> > Remember that I also connected socket's readyRead() to socketReady()
> > slot? So, when socketReady() signal is called, I know data has arrived
> > at the socket, and that it has already been fed to my xmlStreamReader.
> > So inside socketReady() signal I simply call parser.parse().
> >
> > This is basically it. You should try some approach like this for
> > yourself. It is like math, if you never try it yourself, you will never
> > learn. I don't know if I was able to really convey what I mean, I am not
> > a very good writer, you know.
> >
> > Refer on Google to "Incremental Xml Parsing". This will give you more
> > background on how QXmlStreamReader works.
> >
> > Rafael
> >
> >
> >
> >
> >
> > Bo Thorsen wrote:
> > > On onsdag den 27. Februar 2008, Rafael Roquetto wrote:
> > >
> > >> As Thiago said, that is how TCP works.
> > >>
> > >> I suggest you use QXmlStreamReader to parse data from socket. You can
> > >> use QXmlStreamReader::setDevice() and pass a socket fd to it.
> > >> Then, whenever data arrives, it tries to parse. If the xml is not
> > >> complete, the parser will return a premature end of document, keeping
> > >> its state.
> > >> This is what you should do, IMHO.
> > >>
> > >
> > > Another solution is to do a simple extension. Instead of sending just
> the XML
> > > file, send first a single line with the number of bytes in the XML file.
> Then
> > > it's easy to wait until the entire amount of data is available before
> > > actually reading it.
> > >
> > > Planning for split packages also makes it a lot easier to later take the
> > > application to do network communication on more than one machine. If you
> > > don't get this right from the beginning, you're going to have debugging
> hell.
> > >
> > > At first, I thought this problem was that the OP was concerned about
> speed.
> > > But since he's using XML for the communications, I guess the network
> speed is
> > > irrelevant.
> > >
> > > Bo.
> > >
> > >
> > >> | pedro mateo || wrote:
> > >> |
> > >>
> > >>> Hi!!
> > >>>
> > >>> On Tue, Feb 26, 2008 at 7:49 PM, Rafael Roquetto
> > >>> <rafaelroquetto@xxxxxxxxx <mailto:rafaelroquetto@xxxxxxxxx>> wrote:
> > >>>
> > >>> On Tue, Feb 26, 2008 at 3:42 PM, | pedro mateo ||
> > >>>
> > >>> <pedrolmn@xxxxxxxxx <mailto:pedrolmn@xxxxxxxxx>> wrote:
> > >>> > First, thanks!!
> > >>> >
> > >>> > I think MTU shouldn't be the reason of my trouble because
> > >>>
> > >>> Routers uses it to
> > >>>
> > >>> > split data when it is necessary, but my data is always on my
> > >>>
> > >>> computer, I
> > >>>
> > >>> > don't use my LAN to send something.
> > >>>
> > >>> Yet, you are probably using the loopback interface, which relies
> on
> > >>> tcp packets. So MTU does matter.
> > >>>
> > >>> But just for curiosity, whats the problem with segmentation?
> > >>>
> > >>>
> > >>> I'm using TCP to send xml data.
> > >>> When a new TCP packet arrives, socket emits Readyread signal and I get
> > >>> all the text I need.
> > >>> If XML text is fragmented in two packets, I will receive two readyread
> > >>> signals, therefore I will receive two different XML strings, each one
> > >>> a half of the original XML string.
> > >>> I need to get only one XML string like the original (1 xml string = 1
> > >>> event).
> > >>>
> > >>> When I receive the first readyread signal, I could wait for the second
> > >>> one, but I can't be sure if the new received data belongs to the last
> > >>> TCP packet, it may be a new TCP packet.
> > >>>
> > >>> cheers!!
> > >>>
> > >>> > Cheers!!!
> > >>> >
> > >>> >
> > >>> >
> > >>> > On Tue, Feb 26, 2008 at 7:34 PM, Thiago Macieira
> > >>> > <thiago.macieira@xxxxxxxxxxxxx
> > >>>
> > >>> <mailto:thiago.macieira@xxxxxxxxxxxxx>> wrote:
> > >>> > > On Tuesday 26 February 2008 19:17:40 | pedro mateo || wrote:
> > >>> > > > I am sending data across two different processes using a TCP
> > >>> >
> > >>> > (QTcpSocket)
> > >>> >
> > >>> > > > channel and localhost address.
> > >>> > > > Now I am surprised because I have seen on wireshark that TCP
> > >>>
> > >>> (and
> > >>>
> > >>> > obviously
> > >>> >
> > >>> > > > IP) uses two packets to send 20000 bytes of data.
> > >>> > > > I don't know why TCP uses two packets if communication is in
> > >>>
> > >>> my own PC,
> > >>>
> > >>> > Do
> > >>> >
> > >>> > > > ip is to blame?
> > >>> > > > My query is:
> > >>> > > > how can I avoid fragmentation with QTcpSocket? I have used
> > >>> > > > "setReadBufferSize(0) = unlimited buffer" but it doesn't
> work.
> > >>> > > > Any idea?
> > >>> > >
> > >>> > > This is below QTcpSocket's level. Your operating system
> > >>>
> > >>> decided that it
> > >>>
> > >>> > wanted
> > >>> >
> > >>> > > to send the whole thing in one TCP packet, instead of
> splitting
> > >>> > > it
> > >>> >
> > >>> > according
> > >>> >
> > >>> > > to the MTU and sending serially.
> > >>> > >
> > >>> > > --
> > >>> > > Thiago José Macieira - thiago.macieira AT trolltech.com
> > >>>
> > >>> <http://trolltech.com>
> > >>>
> > >>> > > Trolltech ASA - Sandakerveien 116, NO-0402 Oslo, Norway
> > >>> >
> > >>> > --
> > >>> > Pedro Luis Mateo Navarro || pedrolmn@xxxxxxxxx
> > >>>
> > >>> <mailto:pedrolmn@xxxxxxxxx> _ pedromateo@xxxxxxxxx
> > >>> <mailto:pedromateo@xxxxxxxxx>
> > >>>
> > >>> > > _phone: (+34) 626 14 29 33 or (+34) 968 39 82 58
> > >>> > > _web: www.pedromana.com <http://www.pedromana.com>
> > >>> > > _msn: pedrolmn@xxxxxxxxxxx <mailto:pedrolmn@xxxxxxxxxxx>
> > >>>
> > >>> --
> > >>> Pedro Luis Mateo Navarro || pedrolmn@xxxxxxxxx
> > >>> <mailto:pedrolmn@xxxxxxxxx> _ pedromateo@xxxxxxxxx
> > >>> <mailto:pedromateo@xxxxxxxxx>
> > >>>
> > >>> > _phone: (+34) 626 14 29 33 or (+34) 968 39 82 58
> > >>> > _web: www.pedromana.com <http://www.pedromana.com>
> > >>> > _msn: pedrolmn@xxxxxxxxxxx <mailto:pedrolmn@xxxxxxxxxxx>
> > >>>
> > >> --
> > >> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> > >> "unsubscribe" in the subject or the body. List archive and information:
> > >> http://lists.trolltech.com/qt-interest/
> > >>
> > >
> > >
> > >
> > >
> >
> > --
> > To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> > List archive and information: http://lists.trolltech.com/qt-interest/
> >
> >
>
>
>
> --
> Pedro Luis Mateo Navarro || pedrolmn@xxxxxxxxx _ pedromateo@xxxxxxxxx
>
> > _phone: (+34) 626 14 29 33 or (+34) 968 39 82 58
> > _web: www.pedromana.com
> > _msn: pedrolmn@xxxxxxxxxxx
--
[ signature omitted ]
Hi!!!
On Wed, Feb 27, 2008 at 6:55 PM, Rafael Roquetto <rafaelroquetto@xxxxxxxxx>
wrote:
> What happens if it receives
> <clos
> in one chuck of data
> and
> e-tag/> in another?
When I receive new data, I do:
buffer += newString;
if (buffer.endsWith(<closeTag>))
{
}
>
>
> On Wed, Feb 27, 2008 at 2:43 PM, | pedro mateo || <pedrolmn@xxxxxxxxx>
> wrote:
> > Thanks to all!!
> >
> > Finally, I have solved my trouble in an "upper layer".
> > If XMLControl (wich uses QTcpSocket) receives a xml string without the
> > </close-tag>, it stores the string. When it receives this tag, it
> manages
> > it.
> >
> > I think that is the simplest solution, despite I wanted to manage that
> > trouble at the socket-level at first.
> >
> > Cheers!!
> >
> > PS: sorry my english, I really have to improve it. ;-P
> >
> >
> >
> > On Wed, Feb 27, 2008 at 12:24 PM, Rafael Roquetto
> > <rafaelroquetto@xxxxxxxxx> wrote:
> > > Pedro, here is what I did when I needed to parse XML data coming
> across
> > > network, in a toll road system:
> > >
> > > I have this class, called Lane, which has a socket attribute and a
> > > socketReady() slot. The first thing I did was connecting socketReady()
> > > slot to the socket's readyRead() signal, as in
> > >
> > > connect(socket, SIGNAL(readyRead()),
> > > this, SLOT(socketReady()));
> > >
> > > This Lane class also has a parser attribute of the type Parser. Parser
> > > is a class I implemented descending from QObject, and it takes a
> > > reference to a QXmlStreamReader on its constructor. It has a method
> > > called Parser::parse(), implemented as follows:
> > >
> > >
> > > void Parser::parse()
> > > {
> > > QXmlStreamReader::TokenType tokenType;
> > > QStringRef name;
> > >
> > > while(!xml.atEnd())
> > > {
> > > tokenType = xml.readNext();
> > >
> > > name = xml.name();
> > >
> > > if(tokenType == QXmlStreamReader::StartElement)
> > > {
> > > if(name == "stream")
> > > handleStream();
> > > else if(name == "message")
> > > currentHandler = MESSAGE;
> > > }
> > > else if(tokenType == QXmlStreamReader::Characters)
> > > {
> > > if(currentHandler == MESSAGE)
> > > handleMessage();
> > > }
> > > else if(tokenType == QXmlStreamReader::EndElement)
> > > {
> > > if(currentHandler == MESSAGE)
> > > currentHandler = DEFAULT;
> > > }
> > > }
> > >
> > > if(xml.hasError())
> > > logger.debug(xml.errorString());
> > > }
> > >
> > > This method tried to parse the XML present on QXmlStreamReader. Note
> > > that the while loop condition is "!xml.atEnd()". It will abort in case
> > > the XML document is yet incomplete (i.e. only a chunk of data has
> > > arrived to feed QXmlStreamReader), however, it will save its state and
> > > you will be able to proceed once more data has been fed to
> > QXmlStreamReader.
> > >
> > > How is that fed?
> > >
> > > In my Lane class, I also create an instance of QXmlStreamReader, and
> > > calls xmlStreamReader.setDevice(socket);
> > > This will feed QXmlStreamReader with data coming from the socket.
> > > Remember that I also connected socket's readyRead() to socketReady()
> > > slot? So, when socketReady() signal is called, I know data has arrived
> > > at the socket, and that it has already been fed to my xmlStreamReader.
> > > So inside socketReady() signal I simply call parser.parse().
> > >
> > > This is basically it. You should try some approach like this for
> > > yourself. It is like math, if you never try it yourself, you will
> never
> > > learn. I don't know if I was able to really convey what I mean, I am
> not
> > > a very good writer, you know.
> > >
> > > Refer on Google to "Incremental Xml Parsing". This will give you more
> > > background on how QXmlStreamReader works.
> > >
> > > Rafael
> > >
> > >
> > >
> > >
> > >
> > > Bo Thorsen wrote:
> > > > On onsdag den 27. Februar 2008, Rafael Roquetto wrote:
> > > >
> > > >> As Thiago said, that is how TCP works.
> > > >>
> > > >> I suggest you use QXmlStreamReader to parse data from socket. You
> can
> > > >> use QXmlStreamReader::setDevice() and pass a socket fd to it.
> > > >> Then, whenever data arrives, it tries to parse. If the xml is not
> > > >> complete, the parser will return a premature end of document,
> keeping
> > > >> its state.
> > > >> This is what you should do, IMHO.
> > > >>
> > > >
> > > > Another solution is to do a simple extension. Instead of sending
> just
> > the XML
> > > > file, send first a single line with the number of bytes in the XML
> file.
> > Then
> > > > it's easy to wait until the entire amount of data is available
> before
> > > > actually reading it.
> > > >
> > > > Planning for split packages also makes it a lot easier to later take
> the
> > > > application to do network communication on more than one machine. If
> you
> > > > don't get this right from the beginning, you're going to have
> debugging
> > hell.
> > > >
> > > > At first, I thought this problem was that the OP was concerned about
> > speed.
> > > > But since he's using XML for the communications, I guess the network
> > speed is
> > > > irrelevant.
> > > >
> > > > Bo.
> > > >
> > > >
> > > >> | pedro mateo || wrote:
> > > >> |
> > > >>
> > > >>> Hi!!
> > > >>>
> > > >>> On Tue, Feb 26, 2008 at 7:49 PM, Rafael Roquetto
> > > >>> <rafaelroquetto@xxxxxxxxx <mailto:rafaelroquetto@xxxxxxxxx>>
> wrote:
> > > >>>
> > > >>> On Tue, Feb 26, 2008 at 3:42 PM, | pedro mateo ||
> > > >>>
> > > >>> <pedrolmn@xxxxxxxxx <mailto:pedrolmn@xxxxxxxxx>> wrote:
> > > >>> > First, thanks!!
> > > >>> >
> > > >>> > I think MTU shouldn't be the reason of my trouble because
> > > >>>
> > > >>> Routers uses it to
> > > >>>
> > > >>> > split data when it is necessary, but my data is always on my
> > > >>>
> > > >>> computer, I
> > > >>>
> > > >>> > don't use my LAN to send something.
> > > >>>
> > > >>> Yet, you are probably using the loopback interface, which
> relies
> > on
> > > >>> tcp packets. So MTU does matter.
> > > >>>
> > > >>> But just for curiosity, whats the problem with segmentation?
> > > >>>
> > > >>>
> > > >>> I'm using TCP to send xml data.
> > > >>> When a new TCP packet arrives, socket emits Readyread signal and I
> get
> > > >>> all the text I need.
> > > >>> If XML text is fragmented in two packets, I will receive two
> readyread
> > > >>> signals, therefore I will receive two different XML strings, each
> one
> > > >>> a half of the original XML string.
> > > >>> I need to get only one XML string like the original (1 xml string
> = 1
> > > >>> event).
> > > >>>
> > > >>> When I receive the first readyread signal, I could wait for the
> second
> > > >>> one, but I can't be sure if the new received data belongs to the
> last
> > > >>> TCP packet, it may be a new TCP packet.
> > > >>>
> > > >>> cheers!!
> > > >>>
> > > >>> > Cheers!!!
> > > >>> >
> > > >>> >
> > > >>> >
> > > >>> > On Tue, Feb 26, 2008 at 7:34 PM, Thiago Macieira
> > > >>> > <thiago.macieira@xxxxxxxxxxxxx
> > > >>>
> > > >>> <mailto:thiago.macieira@xxxxxxxxxxxxx>> wrote:
> > > >>> > > On Tuesday 26 February 2008 19:17:40 | pedro mateo ||
> wrote:
> > > >>> > > > I am sending data across two different processes using a
> TCP
> > > >>> >
> > > >>> > (QTcpSocket)
> > > >>> >
> > > >>> > > > channel and localhost address.
> > > >>> > > > Now I am surprised because I have seen on wireshark that
> TCP
> > > >>>
> > > >>> (and
> > > >>>
> > > >>> > obviously
> > > >>> >
> > > >>> > > > IP) uses two packets to send 20000 bytes of data.
> > > >>> > > > I don't know why TCP uses two packets if communication
> is in
> > > >>>
> > > >>> my own PC,
> > > >>>
> > > >>> > Do
> > > >>> >
> > > >>> > > > ip is to blame?
> > > >>> > > > My query is:
> > > >>> > > > how can I avoid fragmentation with QTcpSocket? I have
> used
> > > >>> > > > "setReadBufferSize(0) = unlimited buffer" but it doesn't
> > work.
> > > >>> > > > Any idea?
> > > >>> > >
> > > >>> > > This is below QTcpSocket's level. Your operating system
> > > >>>
> > > >>> decided that it
> > > >>>
> > > >>> > wanted
> > > >>> >
> > > >>> > > to send the whole thing in one TCP packet, instead of
> > splitting
> > > >>> > > it
> > > >>> >
> > > >>> > according
> > > >>> >
> > > >>> > > to the MTU and sending serially.
> > > >>> > >
> > > >>> > > --
> > > >>> > > Thiago José Macieira - thiago.macieira AT trolltech.com
> > > >>>
> > > >>> <http://trolltech.com>
> > > >>>
> > > >>> > > Trolltech ASA - Sandakerveien 116, NO-0402 Oslo, Norway
> > > >>> >
> > > >>> > --
> > > >>> > Pedro Luis Mateo Navarro || pedrolmn@xxxxxxxxx
> > > >>>
> > > >>> <mailto:pedrolmn@xxxxxxxxx> _ pedromateo@xxxxxxxxx
> > > >>> <mailto:pedromateo@xxxxxxxxx>
> > > >>>
> > > >>> > > _phone: (+34) 626 14 29 33 or (+34) 968 39 82 58
> > > >>> > > _web: www.pedromana.com <http://www.pedromana.com>
> > > >>> > > _msn: pedrolmn@xxxxxxxxxxx <mailto:pedrolmn@xxxxxxxxxxx
> >
> > > >>>
> > > >>> --
> > > >>> Pedro Luis Mateo Navarro || pedrolmn@xxxxxxxxx
> > > >>> <mailto:pedrolmn@xxxxxxxxx> _ pedromateo@xxxxxxxxx
> > > >>> <mailto:pedromateo@xxxxxxxxx>
> > > >>>
> > > >>> > _phone: (+34) 626 14 29 33 or (+34) 968 39 82 58
> > > >>> > _web: www.pedromana.com <http://www.pedromana.com>
> > > >>> > _msn: pedrolmn@xxxxxxxxxxx <mailto:pedrolmn@xxxxxxxxxxx>
> > > >>>
> > > >> --
> > > >> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxxxxxx
> > > >> "unsubscribe" in the subject or the body. List archive and
> information:
> > > >> http://lists.trolltech.com/qt-interest/
> > > >>
> > > >
> > > >
> > > >
> > > >
> > >
> > > --
> > > To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> > "unsubscribe" in the subject or the body.
> > > List archive and information: http://lists.trolltech.com/qt-interest/
> > >
> > >
> >
> >
> >
> > --
> > Pedro Luis Mateo Navarro || pedrolmn@xxxxxxxxx _ pedromateo@xxxxxxxxx
> >
> > > _phone: (+34) 626 14 29 33 or (+34) 968 39 82 58
> > > _web: www.pedromana.com
> > > _msn: pedrolmn@xxxxxxxxxxx
>
--
[ signature omitted ]
Sorry, Gmail and shortcuts ;-P
On Wed, Feb 27, 2008 at 8:16 PM, | pedro mateo || <pedrolmn@xxxxxxxxx>
wrote:
> Hi!!!
>
> On Wed, Feb 27, 2008 at 6:55 PM, Rafael Roquetto <rafaelroquetto@xxxxxxxxx>
> wrote:
>
> > What happens if it receives
> > <clos
> > in one chuck of data
> > and
> > e-tag/> in another?
>
>
When I receive new data, I do:
buffer += newXmlString;
if (buffer.endsWith(<closeTag>)) consumeXml(buffer);
else return; //wait for new incoming data
I'm sure a flush was done when new xmlString was sent.
Cheers!!
>
>
> >
> > On Wed, Feb 27, 2008 at 2:43 PM, | pedro mateo || <pedrolmn@xxxxxxxxx>
> > wrote:
> > > Thanks to all!!
> > >
> > > Finally, I have solved my trouble in an "upper layer".
> > > If XMLControl (wich uses QTcpSocket) receives a xml string without the
> > > </close-tag>, it stores the string. When it receives this tag, it
> > manages
> > > it.
> > >
> > > I think that is the simplest solution, despite I wanted to manage that
> > > trouble at the socket-level at first.
> > >
> > > Cheers!!
> > >
> > > PS: sorry my english, I really have to improve it. ;-P
> > >
> > >
> > >
> > > On Wed, Feb 27, 2008 at 12:24 PM, Rafael Roquetto
> > > <rafaelroquetto@xxxxxxxxx> wrote:
> > > > Pedro, here is what I did when I needed to parse XML data coming
> > across
> > > > network, in a toll road system:
> > > >
> > > > I have this class, called Lane, which has a socket attribute and a
> > > > socketReady() slot. The first thing I did was connecting
> > socketReady()
> > > > slot to the socket's readyRead() signal, as in
> > > >
> > > > connect(socket, SIGNAL(readyRead()),
> > > > this, SLOT(socketReady()));
> > > >
> > > > This Lane class also has a parser attribute of the type Parser.
> > Parser
> > > > is a class I implemented descending from QObject, and it takes a
> > > > reference to a QXmlStreamReader on its constructor. It has a method
> > > > called Parser::parse(), implemented as follows:
> > > >
> > > >
> > > > void Parser::parse()
> > > > {
> > > > QXmlStreamReader::TokenType tokenType;
> > > > QStringRef name;
> > > >
> > > > while(!xml.atEnd())
> > > > {
> > > > tokenType = xml.readNext();
> > > >
> > > > name = xml.name();
> > > >
> > > > if(tokenType == QXmlStreamReader::StartElement)
> > > > {
> > > > if(name == "stream")
> > > > handleStream();
> > > > else if(name == "message")
> > > > currentHandler = MESSAGE;
> > > > }
> > > > else if(tokenType == QXmlStreamReader::Characters)
> > > > {
> > > > if(currentHandler == MESSAGE)
> > > > handleMessage();
> > > > }
> > > > else if(tokenType == QXmlStreamReader::EndElement)
> > > > {
> > > > if(currentHandler == MESSAGE)
> > > > currentHandler = DEFAULT;
> > > > }
> > > > }
> > > >
> > > > if(xml.hasError())
> > > > logger.debug(xml.errorString());
> > > > }
> > > >
> > > > This method tried to parse the XML present on QXmlStreamReader. Note
> > > > that the while loop condition is "!xml.atEnd()". It will abort in
> > case
> > > > the XML document is yet incomplete (i.e. only a chunk of data has
> > > > arrived to feed QXmlStreamReader), however, it will save its state
> > and
> > > > you will be able to proceed once more data has been fed to
> > > QXmlStreamReader.
> > > >
> > > > How is that fed?
> > > >
> > > > In my Lane class, I also create an instance of QXmlStreamReader, and
> > > > calls xmlStreamReader.setDevice(socket);
> > > > This will feed QXmlStreamReader with data coming from the socket.
> > > > Remember that I also connected socket's readyRead() to socketReady()
> > > > slot? So, when socketReady() signal is called, I know data has
> > arrived
> > > > at the socket, and that it has already been fed to my
> > xmlStreamReader.
> > > > So inside socketReady() signal I simply call parser.parse().
> > > >
> > > > This is basically it. You should try some approach like this for
> > > > yourself. It is like math, if you never try it yourself, you will
> > never
> > > > learn. I don't know if I was able to really convey what I mean, I am
> > not
> > > > a very good writer, you know.
> > > >
> > > > Refer on Google to "Incremental Xml Parsing". This will give you
> > more
> > > > background on how QXmlStreamReader works.
> > > >
> > > > Rafael
> > > >
> > > >
> > > >
> > > >
> > > >
>