For the reference of others, I was having a problem using Bind because I was using the UdpClient class and accessing its internal Socket (via UdpClient.Client) which would throw a SocketException no matter how I tried to Bind. My workaround relies on creating and binding the Socket first, then assigning it to the UdpClient instance:
using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp))
{
var endPoint = new IPEndPoint(ip, port);
socket.Bind(endPoint);
using (var client = new UdpClient() {Client = socket})
{
var destinationIP = IPAddress.Broadcast;
client.Connect(destinationIP, port);
client.Send(bytes, bytes.Length);
}
}