A simple experiment in python (on Windows) shows that I can bind to the same address at the same time for both a wildcard address and a specific address:
import socket
import select
MY_PORT = 13337
sany = socket.socket()
sany.bind(('', MY_PORT))
sany.listen(0)
sloc = socket.socket()
sloc.bind(('127.0.0.1', MY_PORT))
sloc.listen(0)
socks = [sany, sloc]
ready, _, _ = select.select(socks, [], [])
print socks.index(ready[0])
Conceptually, they intersect in what they should cover. Continuing the experiment, connecting to ('127.0.0.1', 13337)from another invitation, it is indicated that a more specific "victory" socket is printed (i.e. 1). I see similar behavior on sockets SOCK_DGRAM.
My questions are as follows:
- Is this behavior contractual (Winsock, Berkeley Sockets, etc.)?
- How should this behave for multicast sockets?
- How should this behave on * nix systems?