# Comparing TCP sockets

**URL:** <https://www.ruby-forum.com/t/comparing-tcp-sockets/145788>\
**Category:** Ruby\
**Created:** [August 13, 2008, 11:11pm UTC](https://www.ruby-forum.com/t/comparing-tcp-sockets/145788 "2008-08-13T23:11:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ISSSSaki\_Baz\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/51bf81/32.png) [@ISSSSaki\_Baz\_C](https://www.ruby-forum.com/u/ISSSSaki_Baz_C)\
**Post date:** [August 13, 2008, 11:11pm UTC](https://www.ruby-forum.com/t/comparing-tcp-sockets/145788/1 "2008-08-13T23:11:36Z")

</div>

Hi, imagine I receive a TCP connection and I store the TCPSocket in a  
variable “io\_1”:

io\_1 = io

If I do “io\_1.peeraddr” I can see the remote address.

If latter the connection is closed by the peer and I do “io\_1.peeraddr”  
then I  
get an Exception because socket closed (ok).

Imagine later the _same_ connection is received and I store it in  
“io\_2”.  
Will “io\_1 == io\_2” return true? or should I compare “peeraddr” Array  
fields  
one by one (address, port…)?

Thanks.

---

<div class="post-metadata">

**Author:** ![ISSSSaki\_Baz\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/51bf81/32.png) [@ISSSSaki\_Baz\_C](https://www.ruby-forum.com/u/ISSSSaki_Baz_C)\
**Post date:** [August 14, 2008, 1:49am UTC](https://www.ruby-forum.com/t/comparing-tcp-sockets/145788/2 "2008-08-14T01:49:42Z")

</div>

On Aug 13, 2008, at 14:08 PM, Iñaki Baz C. wrote:

> Imagine later the _same_ connection is received and I store it in  
> “io\_2”.  
> Will “io\_1 == io\_2” return true?

No.

> or should I compare “peeraddr” Array fields one by one (address,  
> port…)?

You can compare the Arrays without going field by field.

---

<div class="post-metadata">

**Author:** ![ISSSSaki\_Baz\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/51bf81/32.png) [@ISSSSaki\_Baz\_C](https://www.ruby-forum.com/u/ISSSSaki_Baz_C)\
**Post date:** [August 14, 2008, 2:23am UTC](https://www.ruby-forum.com/t/comparing-tcp-sockets/145788/3 "2008-08-14T02:23:36Z")

</div>

El Jueves, 14 de Agosto de 2008, Eric H.  
escribió:\> \> get an Exception because socket closed (ok).

> > Imagine later the _same_ connection is received and I store it in  
> > “io\_2”.  
> > Will “io\_1 == io\_2” return true?
> 
> No.

Thanks.
