denniskuczynski/simple_upnp — pull request #4 by Burgestrand (2013-08-21 06:02:07+00:00)
Title: Allow SSDP discovery to work even when the socket is being listened to

Upon starting a find, simple_upnp crashes because it appear something else is already listening on the same port on my computer.

```
/Users/Kim/.rvm/gems/ruby-2.0.0-p247/gems/simple_upnp-0.0.4/lib/simple_upnp/discovery.rb:42:in `bind': Address already in use - bind(2) (Errno::EADDRINUSE)
from /Users/Kim/.rvm/gems/ruby-2.0.0-p247/gems/simple_upnp-0.0.4/lib/simple_upnp/discovery.rb:42:in `open_socket'
from /Users/Kim/.rvm/gems/ruby-2.0.0-p247/gems/simple_upnp-0.0.4/lib/simple_upnp/discovery.rb:28:in `find'
```

Setting the socket option SO_REUSEADDR allows the socket to be listened to even if another application is already listening on the same host and port. In practice, this means both applications listening will receive packets on the socket, so it won’t interfere with whatever other application is listening on the socket.