[Live-devel] Unicast, Socket Bind Issues on localhost?
Hubert Pham
hubert at csail.mit.edu
Tue Feb 6 10:24:16 PST 2007
Hi,
I'm trying to use testMP3Sender and testMP3Receiver to stream an MP3 file
via unicast. I've modified the examples appropriately for unicast
streaming: testMP3Sender sends to a target unicast address, while
testMP3Receiver listens on 0.0.0.0.
This works fine---except when a) the sender is sending to a receiver on the
same host, and b) the receiver starts up before the sender. Under this
scenario, the receiver never receives any packets; more precisely, the
receiver's select() never indicates that the socket is readable. If instead
the sender starts before the receiver, then the setup works fine (except
the receiver obviously doesn't receive the first few initial packets).
Additionally, if using multicast instead of unicast, then everything also
works fine regardless of startup order.
My guess is that GroupsockHelper.cpp::setupDatagramSocket (ultimately
called when constructing a Groupsock) attempts to bind the socket to the
user-specified port if the port is non-zero, disregarding whether or not
the socket is intended as send-only to a unicast address:
if (port.num() != 0 || ReceivingInterfaceAddr != INADDR_ANY) {
...
MAKE_SOCKADDR_IN(name, ReceivingInterfaceAddr, port.num());
if (bind(newSocket, (struct sockaddr*)&name, sizeof name) != 0) {
...
I imagine what is happening is that when testMP3Receiver and testMP3Sender
run on the same host, they both try to bind to port 6666 and 6667 on the
same interface. This might make sense when using multicast, but my guess is
that under unicast---in which not all the multicast socket options are
set---one process will lose on the bind and not receive packets.
While streaming data between two processes on the same host might seem like
a corner case, are there any suggestions for doing so? (e.g., a different
available Groupsock interface or constructor parameter?)
Thanks for your time,
hubert
PS I noticed that someone did bring up this issue on March 5, 2002, but I
didn't see a resolution, nor did the post mention anything about the sender
and receiver being on the same host. Apologies if I missed the resolution...
More information about the live-devel
mailing list