-
|
|
UDP Broadcasting/Multicasting in C#/C++
|
Okay, what I'm working on does NOT involve XNA's networking library.
Also, I know that this CAN be done, it's just a little impractical, but I'll figure that out once I get a little farther along.
Anyway, broadcasting is the means by which you send a packet to all of the receiving computers on a particular network. This is done by making one or more of the ranges in the IP 255.
So for example, 192.1.255.255. This sends it to every computer within those particular ranges. This is useful in networking for a game application to find a server, or a chat program, etc.
A GLOBAL broadcast, is one in which you send a packet to every computer. Every one of them on the internet. This is done by making the IP address only 1's. 255.255.255.255.
Now there hasn't been much use of this for about 10 years, since the internet really started taking off. But it can still be done.
I haven't been able to find out much information about this. Google isn't being very helpful. The only useful results I've gotten have been from Google Books, and a website that is actually the same book from before! So I'm really relying on you guys here to help me out. As stated in the subject, I'm also starting to get back into C++, so if you know of anything there it would help me as well.
Thanks guys,
Archistrage
|
|
-
-
- (8305)
-
premium membership
MVP
-
Posts
6,142
|
Re: UDP Broadcasting/Multicasting in C#/C++
|
it can still be done.
The so-called "Mars datagram." That hasn't been supported for the last 30 years. At the boundary between networks, routers will filter these broadcasts, and not actually broadcast to every host on the internet.
Broadcast actually has to set all the bits of the node-address part of the netmask. Thus, if your network has the address 192.168.0.0/16 (netmask is 255.255.0.0), then you have to broadcast to 192.168.255.255. Because the router will not forward broadcasts to other networks anyway, the easiest thing to do is to always broadcast to 255.255.255.255 whenever you need to broadcast. That means that you don't have to use (OS- and machine-dependent) means of finding out the proper interface and network address to broadcast on. However, some bridged networks actually will filter "Mars" at the bridge, but let properly "network addressed" broadcasts through, so there is a marginal benefit in going through that pain.
Also note that sockets generally need to be enabled for supporting broadcast packets; SO_BROADCAST in BSD/WinSock, and some property on the .NET socket object.
It's unclear what your question really is, though. What, specifically, are you trying to do, what have you tried, and what do you need help with? Is this a request for code, for documentation pointers, or something else?
Jon Watte, Direct3D MVP Tweets, occasionallykW X-port 3ds Max .X exporter kW Animation source code
|
|
-
-
- (858)
-
premium membership
-
Posts
521
|
Re: UDP Broadcasting/Multicasting in C#/C++
|
It isn't so much that 255 is a magic number for broadcasting, as it is a coincidence. For every subnet, the first and last address are reserved for special purposes. The last address is called the broadcast address and meant for just that, broadcasting to the entire subnet. So, for a class C, you are right, the broadcast address would be x.x.x.255.
However, try as you might, most routers will drop broadcast requests without additional setup options. They have to or we would all be flooded with DHCP requests. So, you won't have much luck with the 'global' broadcast.
EDIT: Jwatte beat me
|
|
-
|
|
Re: UDP Broadcasting/Multicasting in C#/C++
|
Okay thanks.
Yeah, I did a crappy job of wording this. What I wanted to know is if anyone here has found a way to do it. Wasn't really a question so much as getting a feel for it. I haven't done anything yet. I'm essentially in my research phase, mainly because this is pretty much uncharted territory.
I know that the some routers will ignore these packets, so do you guys know what it is in the router that needs to be configured to allow it to pass through or be received?
Thanks guys,
Jacob
|
|
-
-
- (858)
-
premium membership
-
Posts
521
|
Re: UDP Broadcasting/Multicasting in C#/C++
|
They just need to be configured to allow for broadcast forwarding. I wouldn't say it is exactly uncharted territory. Like I said, DHCP requests are all broadcasts. What is it you plan to try with broadcasts?
|
|
-
|
|
Re: UDP Broadcasting/Multicasting in C#/C++
|
I'm looking at ways for utilizing networks that don't have a central server with a static IP. I've been doing some research, which includes emailing several internet providers, and I've found out that pretty much all IP's won't change your dynamic IP as long as you're on the internet. I've also read that a lot of people have their dynamic IP stay the same, sometimes for years at a time. I'm looking into building an open source class that would allow for gamer servers/P2P games or even chat apps to connect to each other without having a central (static IP) server to monitor their IP address.
Well, that's all in the future. Right now I'm planning on making a P2P email app, just so I can get used to global broadcasting, and letting me figure them out. I don't plan on releasing it, mainly just use it for fun within my family. I'll use AES encryption on the messages.
Archistrage
|
|
-
-
- (858)
-
premium membership
-
Posts
521
|
Re: UDP Broadcasting/Multicasting in C#/C++
|
I think you are going to have issues with that. The routers that drop broadcast packets (which is most not some) do so for their own protection. Not only from a denial of service aspect, but also from a security standpoint. Broadcasts can advertise specific IPs in use and what software they are using based on the types of broadcasts being used. Malicious software can use that to their advantage to pinpoint attacks.
|
|
-
|
|
Re: UDP Broadcasting/Multicasting in C#/C++
|
Hmmm, that is a good point. As I said, I was planning on using AES encryption. Is there anyway to not allow or encrypt that kind of information, and I could disable that feature on the router? As I said, for now this is staying within my family for now, and until I find a more practical way I don't intend to release whatever I write.
Archistrage
|
|
-
-
- (858)
-
premium membership
-
Posts
521
|
Re: UDP Broadcasting/Multicasting in C#/C++
|
You can do a lot with some complex firewall and routing rules. However, my point was that it would only be effective internally. So, unless your family all resides on the same network, your main problem is going to be all the routers between you and your family members. If you are all on the same network, then there is no problem. You can leave your routers untouched and the broadcasts will happily traverse your internal network.
|
|
-
-
- (8305)
-
premium membership
MVP
-
Posts
6,142
|
Re: UDP Broadcasting/Multicasting in C#/C++
|
if anyone here has found a way to do it
To do what? You still haven't actually specified what it is you want to do.
It seems like you want to send a Mars datagram. It turns out, you can only get that to pass the routers that you control, and only if those routers can be configured to allow it (which many cannot). Thus, you're probably better off just doing a network-specific broadcast if you want, say, available game advertising to work across a network bridge.
Jon Watte, Direct3D MVP Tweets, occasionallykW X-port 3ds Max .X exporter kW Animation source code
|
|
-
|
|
Re: UDP Broadcasting/Multicasting in C#/C++
|
Sorry I've been busy for a while and haven't had a chance to check up in a while.
Yes, I am working on sending a Mars datagram. Haven't had much luck yet.
One thing that's confusing me though, how do other games make server lists then, such as open source games? Where, when you open up the networking menu, it's blank at first, then it lists all the servers it can find? How does it know which servers are available? Do they have a centralized server, that all the other servers connect to, to say that they're available and what they're IP address is? Then the clients connect to that central server to retrieve that list?
Or is it just another language with different options for broadcasting, and different protocols?
That's kind of like what I'm getting at here? I've assumed that they're are several open source games that can't afford a static IP, so they use an option like this? I'm beginning to rethink that theory though.
Archistrage
|
|
-
|
|
Re: UDP Broadcasting/Multicasting in C#/C++
|
archistrage:Do they have a centralized server, that all the other servers connect to, to say that they're available and what they're IP address is? Then the clients connect to that central server to retrieve that list?
Yep, that's how it's done. There exist services that make it so that not each game has to run its own central server (GGZ and ASE, for example, and possibly Steam and GameSpy, though they don't document their internal workings publicly, so I don't know), but mostly everyone runs their own master/meta server.
|
|
-
-
- (13015)
-
Team XNA
-
Posts
8,577
|
Re: UDP Broadcasting/Multicasting in C#/C++
|
archistrage:Yes, I am working on sending a Mars datagram. Haven't had much luck yet.
I would advise changing your approach to this problem. The Internet is carefully designed to make Mars datagrams impossible! If such a thing was possible, just think how many bad guys would use it to send massive DoS attacks! No smart service provider will configure their network to allow such things.
XNA Framework Developer -
blog - homepage
|
|
-
|
|
Re: UDP Broadcasting/Multicasting in C#/C++
|
What about a partial broadcast?
We've already shown that 255.255.255.255 (in theory) should send a broadcast to every computer on the web, however as you've said, ISP's specifically design it so this can't be allowed.
I've also seen (and this does still work) that you can use a broadcast within a local network (as in 192.1.255.255). So what about sending a broadcast to other only computers with a WAN IP within a specific range (i.e. 74.68.255.255) ? Would something such as that work, or is it still within the same problem?
Thanks for your help with this,
Archistrage
|
|
-
-
- (13015)
-
Team XNA
-
Posts
8,577
|
Re: UDP Broadcasting/Multicasting in C#/C++
|
archistrage:So what about sending a broadcast to other only computers with a WAN IP within a specific range (i.e. 74.68.255.255) ?
That may work on some specific networks (especially if you control the network infrastructure you may be able to configure things to make it work), but in general it will not work for the vast majority of Internet users.
If you want two arbitrary users to connect over the Internet, and are not able to control how they connect to the Internet and how their hosting service is configured, you have exactly one option: use a matchmaking service with a fixed address to introduce the two endpoints. There is a reason why every Internet gaming service works this way!
XNA Framework Developer -
blog - homepage
|
|
|