473,804 Members | 2,261 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Upd broadcast on all adapters using sockets

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 sockSendBroadca st = null;
IPEndPoint ipeSendBroadcas t = null;

ipeSendBroadcas t = new IPEndPoint(IPAd dress.Broadcast , iSomePort);

sockSendBroadca st = new Socket(ipeSendB roadcast.Addres sFamily,
SocketType.Dgra m, ProtocolType.Ud p);

sockSendBroadca st.SetSocketOpt ion(SocketOptio nLevel.Socket,
SocketOptionNam e.Broadcast, 1);

sockSendBroadca st.SendTo(Encod ing.ASCII.GetBy tes("blah"),
ipeSendBroadcas t);
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.Broad cast? 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
2 6600
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
Ah right, binding to port 0. I'll try this. Thanks a lot.

May 30 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1769
by: Damir Hakimov | last post by:
Hi All! I'm writing a small programm which must send and service UDP broadcast packets. As start of it I looked at /usr/share/doc/python2.4/Examples/Demo/sockets/broadcast.py damir@debian-IBM:/usr/share/doc/python2.4/examples/Demo/sockets$ python2.4 broadcast.py Traceback (most recent call last):
0
11869
by: Stephan Steiner | last post by:
Hi The project I'm currently working on involves sending large UDP broadcasts. As the .NET framework already provides an easy facility for sending and receiving UDP packets I thought it was a good idea to use UdpClient rather than sockets directly. A few weeks back I ended up rewriting the receiver part to use sockets directly because I had to manipulate some low level socket properties, and those manipulations would fail on the...
1
7850
by: Steve | last post by:
Please take a look at the simple code segment below and advise me what is wrong. According to the help and examples I've seen it should work unless I misunderstand something. The problem is that UdpClient.Receive method always throws following exception, even though I verified that message was successfuly received by devices and responses were sent back:
6
10329
by: pekspro | last post by:
I need some code that gets the address from a server. I read somewhere that you could do this by starting some broadcast server using UDP. The client should send an broadcast message, and when the server answering the client gets the address. But how do I implement this? I did this simple quick-hack: Server: Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
2
2416
by: Shawn G. | last post by:
I'm going around in circles here and need some help. Scenario: I am using (have used) either the UDPClient class or Sockets class to broadcast some bytes to 255.255.255.255 (udp protocol). Upon doing so, a device (of which I will know nothing about) will receive my broadcast and send out a broadcast of its own. Using Ethereal (LAN packet sniffer), I can see my broadcast, and I can see the device broadcast. I cannot however receive...
7
2309
by: GTi | last post by:
I need a code snippet for sending a message to all computers located on the same IP subnet. This is only a simple message like; "Here I am" I'm developing a server/client application. Instead of configuration of each clients where the server is located I want the server to broadcast a simple message that the server is present. This solution must work on a workgroup and domain even if the clients are on different domain/workgroup. Any...
8
3229
by: swell | last post by:
I would like to write a server with the low level API of python ( socket+select and/or socket+thread ) that allow me to register client and update them every X seconds ( could be the time, the temperature, a stock quote, a message , ... ). How to write the server that keep hot connections with clients and update them when events are trigerred. I don't know how to begin this , i look at the python doc but the doc is more related to client...
4
5623
by: =?Utf-8?B?TWFydGlu?= | last post by:
In Device Manager under Network Adapters, nearly all (about 20) items have a yellow warning symbol. The first item, Microsoft 6to4 Adapter says driver is up-to-date BUT says "This device is not working properly because Windows cannot load the drivers required for their device (Code 31). Similar message in all other 20 items under network adapters. Have checked for solutions - send data to Micosoft- but so far no solutions. Any help please?...
1
7621
by: raviskar | last post by:
Hi, I have a problem in receiving UDP broadcast data. We have a simple application which listens for the UDP broadcast data from the external servers. We can receive the UDP broadcast data from one of the servers. For the other external server, our program does not receive any data in the sockets, but we can see the broadcast data in tcpdump capture. Is there any possible reason on why our sockets cannot receive the UDP broadcast, but the...
0
9594
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10346
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10090
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9173
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6863
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4308
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3832
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.