By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,474 Members | 1,001 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,474 IT Pros & Developers. It's quick & easy.

Upd broadcast on all adapters using sockets

P: n/a
Hello,
this might be an easy question, but I don't have any handy solution at
hand. I have an application that is supposed to send UDP broadcast. So
far so easy, I did:

Socket sockSendBroadcast = null;
IPEndPoint ipeSendBroadcast = null;

ipeSendBroadcast = new IPEndPoint(IPAddress.Broadcast, iSomePort);

sockSendBroadcast = new Socket(ipeSendBroadcast.AddressFamily,
SocketType.Dgram, ProtocolType.Udp);

sockSendBroadcast.SetSocketOption(SocketOptionLeve l.Socket,
SocketOptionName.Broadcast, 1);

sockSendBroadcast.SendTo(Encoding.ASCII.GetBytes(" blah"),
ipeSendBroadcast);
That works fine so far, but when I have two in the system (e.g. LAN and
WLAN NIC in different subnets) then it sends the broadcast to the LAN
broadcast address on the LAN adapter only. So I didn't reach any WLAN
devices. What I want to do is send a broadcast the the LAN subnet
broadcast address as well as the WLAN subnet broadcast address. I could
get all local IPs using IPHostEntry of the local machine but how can I
create the corresponding broadcast sockets without binding them to a
specific Port? It is supposed to use the next free port as source port,
just like it does using the code above for one network adapter. For
example is there a way to get the corresponding Subnetbroadcast address
when I have all local IPs retreived from the IPHostEntry to create two
IPEndPoints with instead of using IPAddress.Broadcast? Then the
broadcast to subnet's 2 broadcast address would probably send using
adapter 2...
Thanks in advance and sorry if it's totally easy and I'm to confused to
see the easy way... ;)
Gunnar

May 30 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Gu************@web.de wrote:
That works fine so far, but when I have two in the system (e.g. LAN and
WLAN NIC in different subnets) then it sends the broadcast to the LAN
broadcast address on the LAN adapter only. So I didn't reach any WLAN
devices. <snip>


You are on the right track already. You have to bind one socket to each
network interfaces IP address. If you bind to port 0 it will allocate
the next free port. And use SetSocketOption to enable broadcasting.

hth,
Max
May 30 '06 #2

P: n/a
Ah right, binding to port 0. I'll try this. Thanks a lot.

May 30 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.