Broadcast Address
by Jeremy Alessi · in Torque Game Engine · 03/28/2007 (4:30 pm) · 4 replies
Does anyone know how Torque broadcast queries for LAN servers? I've got one implementation where I'm extracting the network part of the ip address and appending the .255.255 to it (for a B-class network) for example. However, I've heard that you can broadcast to 255.255.255.255 and that should ping all potential servers on the subnet but it doesn't work for me.
I suppose ultimately I'm looking for a way to determine the subnet mask and I'm wondering if Torque does this. I've looked through the code but nothing's jumping out at me yet. Either that or I'm wondering if Torque has some limitations as to what networks it will support for LAN games. As far as I can tell it works fine C and B class networks, which are all I have to test.
Any info at all even if not directly related will be helpful.
I suppose ultimately I'm looking for a way to determine the subnet mask and I'm wondering if Torque does this. I've looked through the code but nothing's jumping out at me yet. Either that or I'm wondering if Torque has some limitations as to what networks it will support for LAN games. As far as I can tell it works fine C and B class networks, which are all I have to test.
Any info at all even if not directly related will be helpful.
About the author
#2
Terms:
WMI = Windows Management Instrumentation ?
CIDR = Classless Inter-Domain Routing ?
Additionally, when you refer to the "shell" and "route print" in Windows can you be more specific?
I am ideally looking to make a .dll or acquire something that already exist that can yield the subnet mask and whatever other information I might need for efficient LAN searching.
03/28/2007 (7:15 pm)
Thanks for the reply. I'm just diving into this really.Terms:
WMI = Windows Management Instrumentation ?
CIDR = Classless Inter-Domain Routing ?
Additionally, when you refer to the "shell" and "route print" in Windows can you be more specific?
I am ideally looking to make a .dll or acquire something that already exist that can yield the subnet mask and whatever other information I might need for efficient LAN searching.
#3
In engine\game\net\serverQuery.cc
That's how I found out Torque's broadcasting method for pinging other servers. I used that code to create a secondary UDP socket for broadcasting and receiving special data for my new network protocol, which is unrelated to typical Torque game code.
If you need another example, help with breaking down that code section, or whatever, just let me know. . .
03/28/2007 (7:19 pm)
I just found this section of code a few weeks ago while creating some new network protocol, here's what I can provide:In engine\game\net\serverQuery.cc
void queryLanServers(...,...,...) [b]// Didn't feel like typing full parameter list[/b]
{
[b]....// Bunch of other code[/b]
NetAddress addr;
char addrText[256];
[b]dSprintf(addrText, sizeof(addrText), "IP:BROADCAST:%d", port);
Net::stringToAddress(addrText, &addr);[/b]
pushPingBroadcast(%addr);
Con::executef(4, "onServerQueryStatus", "start", "Querying LAN servers", "0");
processPingsAndQueries(gPingSession);
}That's how I found out Torque's broadcasting method for pinging other servers. I used that code to create a secondary UDP socket for broadcasting and receiving special data for my new network protocol, which is unrelated to typical Torque game code.
If you need another example, help with breaking down that code section, or whatever, just let me know. . .
#4
You could use this to retrieve information on the local NICs.
"shell" is the Windows shell... "Start->Run", type "cmd", hit return.
Typing "route print" there will show you network route information.
There might already be a C/C++ library to get to the information you need... I'm not sure.
It's not a lot of code though.
As a first step, it would be worth stepping through with the debugger to see why the all-ones broadcast fails. Perhaps there is some bug in serverQuery.cc (presuming you are using that).
03/29/2007 (9:32 am)
Yes, WMI is Windows Management Instrumentation. Sorry.You could use this to retrieve information on the local NICs.
"shell" is the Windows shell... "Start->Run", type "cmd", hit return.
Typing "route print" there will show you network route information.
There might already be a C/C++ library to get to the information you need... I'm not sure.
It's not a lot of code though.
As a first step, it would be worth stepping through with the debugger to see why the all-ones broadcast fails. Perhaps there is some bug in serverQuery.cc (presuming you are using that).
Tim McClarren
Default Studio Name
However, there are ways to retrieve this information for a given NIC configuration if you map the IP address to the NIC. One way would be to use WMI on Windows. On Linux, you can read from /proc. This would be much better than trying to guess the class of the network (which would never work on CIDR-addressed subnets, anyways).
I don't think Torque should have any issues with supporting all classes of IP, the networking code deals with the socket API.
BTW, unless you know the subnet mask, you can't reliably extract the network part of the IP address (but, you probably already know that, hence the desire to get it).
Also, if you're trying this on Windows, look to see what you get with "route print" in the shell (for the "all ones" broadcast). I'm assuming the server machines are on the same network segment?