I found the problem, and I think it's a bug in the current version of
ns-3. Here is the udp-socket-impl.cc "Connect" function:
int
UdpSocketImpl::Connect(const Address & address)
{
NS_LOG_FUNCTION (this << address);
InetSocketAddress transport = InetSocketAddress::ConvertFrom
(address);
m_defaultAddress = transport.GetIpv4 ();
m_defaultPort = transport.GetPort ();
NotifyConnectionSucceeded ();
m_connected = true;
return 0;
}
Notice how "NotifyConnectionSucceeded ();" is being called before
m_connected is set to true. So what was happening was that the
connection handler callback was being called before m_connected got
set, and I was trying to send data on a socket that wasn't considered
to be connected yet. When I switch "NotifyConnection..." and
"m_connected...", my code works as expected.
I realize that UDP is connectionless, so using connection-oriented
callbacks may seem unnecessary. My code originally used TCP, but I
switched to UDP to leverage multicasting and I left much of the
original code in place. I would agree that using the callbacks is
unnecessary, but be that as it may, the API still supports their use.
In fact, the API supports setting lots of connection-oriented event
handlers on connectionless protocols, and most of these event handlers
simply never get called. However, in this case, the outgoing
connection handler was being called. So either the event handler
shouldn't get called at all, or it should get called once m_connected
is set to true so it will behave properly.
~ Steve