Forum: Ruby How to Distinguish between a Reset packet and a Normal one

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
0db083e56e4d69540df2ec1b00f40582?d=identicon&s=25 sairam MP (sai438)
on 2007-03-22 05:29
How to Distinguish between reset packet and a normal packet?? Here I am
using TCPSocket API where in Iam Using recvfrom().
E7559e558ececa67c40f452483b9ac8c?d=identicon&s=25 Gary Wright (Guest)
on 2007-03-22 06:19
(Received via mailing list)
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
0db083e56e4d69540df2ec1b00f40582?d=identicon&s=25 sairam MP (sai438)
on 2007-03-22 09:52
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
E7559e558ececa67c40f452483b9ac8c?d=identicon&s=25 Gary Wright (Guest)
on 2007-03-22 15:52
(Received via mailing list)
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
0db083e56e4d69540df2ec1b00f40582?d=identicon&s=25 sairam MP (sai438)
on 2007-03-29 07:33
> 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.
E7559e558ececa67c40f452483b9ac8c?d=identicon&s=25 Gary Wright (Guest)
on 2007-03-29 08:00
(Received via mailing list)
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.
This topic is locked and can not be replied to.