I'm asking because when a DatagramSocket is constructed, the connected flag is set to true. Which is fine, since you can go:
DatagramSocket s (0x8000);
And read from all adapters to port 0x8000. But if you want to write, you need to call connect first, since connect constructs the sockaddr pointer that is used by the sendto call inside the write method. But if you call connect, it checks if the socket handle is valid and, if it is, closes it and opens a new one. But the new socket is no longer bound to port used in construction, so it isn't suitable for reading anymore.
It seems you could rebind it, but that usage strikes me as odd:
DatagramSocket s (0x8000, true);
s.connect ("255.255.255.255", 0x8000);
s.bind (0x8000); // seems odd...
s.write (somemsg, len);
If the intent is half duplex usage, then it seems like there would need to be a way to set the SO_REUSEADDR socket option in order to implement quite a UDP broadcast type protocols, since you often broadcast and receive on the same port. Actually, there probably should be a way to set the flag anyway. If you are implementing a standard UDP protocol, you'd like to be able to coexist and communicate with other apps on the same machine using the protocol.
There is another issue with using INADDR_ANY for all datagram socket binds for writing, since that translates into the first interface, which can often not be the interface you need (it's never the socket you need on, say, an iPhone). But one question at a time! I first want to make sure I understand the expected usage of the class to start.
Thanks in advance for any feedback/insight!