[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

How to Distinguish between a Reset packet and a Normal one

Purandhar sairam Mannidi

3/22/2007 4:29:00 AM

How to Distinguish between reset packet and a normal packet?? Here I am
using TCPSocket API where in Iam Using recvfrom().

--
Posted via http://www.ruby-....

5 Answers

Gary Wright

3/22/2007 5:19:00 AM

0


On Mar 22, 2007, at 12:29 AM, sairam MP wrote:

> How to Distinguish between reset packet and a normal packet?? Here
> I am
> using TCPSocket API where in Iam Using recvfrom().

You can't. If you are using a TCP socket you don't know where
any packet boundaries are located. TCP only presents a byte
stream to the application.

It sounds like you are describing a situation where data has been
arriving and you are reading it and then for some reason the remote
system decides to abort the TCP connection by sending a TCP RST
packet.

On your end, you'll be able to read all the queued data normally
and then, when you've consumed all the pending data, the next time
you try to read from the socket, an exception will be raised to let
you know that the underlying TCP session has gone away (rather than
being closed cleanly).


Gary Wright




Purandhar sairam Mannidi

3/22/2007 8:53:00 AM

0

Gary Wright wrote:
> On Mar 22, 2007, at 12:29 AM, sairam MP wrote:
>
>> How to Distinguish between reset packet and a normal packet?? Here
>> I am
>> using TCPSocket API where in Iam Using recvfrom().
>
> You can't. If you are using a TCP socket you don't know where
> any packet boundaries are located. TCP only presents a byte
> stream to the application.
>
> It sounds like you are describing a situation where data has been
> arriving and you are reading it and then for some reason the remote
> system decides to abort the TCP connection by sending a TCP RST
> packet.
>
> On your end, you'll be able to read all the queued data normally
> and then, when you've consumed all the pending data, the next time
> you try to read from the socket, an exception will be raised to let
> you know that the underlying TCP session has gone away (rather than
> being closed cleanly).
>
>
> Gary Wright

I think its possible,while receiving some data,if the length of data
received is zero in a blocked receive function then the connection is
said to be reset by peer.

Sairam

--
Posted via http://www.ruby-....

Gary Wright

3/22/2007 2:51:00 PM

0


On Mar 22, 2007, at 4:52 AM, sairam MP wrote:
> I think its possible,while receiving some data,if the length of data
> received is zero in a blocked receive function then the connection is
> said to be reset by peer.

No. A 'reset by peer' is a very specific TCP term. It means that
a packet with the RST bit set has arrived on the connection. It is
possible to have packets that contain no data (keep alive packets
for instance). You can't infer that the connection is dead from
that. But the bigger problem is that you can't even see packet
arrivals from the application. By the time the data gets to
the application the packet boundaries are unknowable. Unless you
are talking about kernel programing you are thinking about TCP
in a very misleading way.

It is a common misunderstanding about TCP that if the sender
writes 100 bytes that the receiver will read 100 bytes. That is,
that the writes of the sender and the reads of the receiver are
always 'paired up'. This is not the way TCP works. Message
boundaries are not preserved across a TCP stream nor does
each call to 'write' correspond to a single packet on the wire.
TCP can coalesce multiple writes into a single packet and can
also split a single write into multiple packets.


Gary Wright




Purandhar sairam Mannidi

3/29/2007 5:34:00 AM

0

> It is a common misunderstanding about TCP that if the sender
> writes 100 bytes that the receiver will read 100 bytes. That is,
> that the writes of the sender and the reads of the receiver are
> always 'paired up'. This is not the way TCP works. Message
> boundaries are not preserved across a TCP stream nor does
> each call to 'write' correspond to a single packet on the wire.
> TCP can coalesce multiple writes into a single packet and can
> also split a single write into multiple packets.
>
>
> Gary Wright

I found that whenever a Reset Packet while data transfer an Exception is
raised (Error::ECONNRESET), I think this can be useful.

--
Posted via http://www.ruby-....

Gary Wright

3/29/2007 5:59:00 AM

0


On Mar 29, 2007, at 1:34 AM, sairam MP wrote:
> I found that whenever a Reset Packet while data transfer an
> Exception is
> raised (Error::ECONNRESET), I think this can be useful.

Yes it is useful. Just understand that the exception is not raised
when the packet *arrives* but when you attempt to read past the last
successfully received byte in the stream.

Perhaps I misunderstood your original question.