hi there, i'm programming a game with multiplayer support.
everything works fine, creating games, logging in etc...as long as i enter the ip of the one that created the game.
Most simple solution: imitate RMI and have a global registry for servers to announce their presence on. All clients are hardcoded to go to the global registry.
Far from ideal, but it would get you a long way
i could solve this by broadcasting the whole lan, and the server answers.
my questions :
1. how to find out the broadcast-adress ? this depends on the subnetmask, and i have no idea how to get it.
Well, not really. 255.255.255.255 is the broadcast address. You should be able to do this from each of your network cards, and it will broadcast on each of your LAN's. You *can* make broadcast addresses for particular networks, and that would be one way of broadcasting to particular interfaces in your PC. Nb: this may or may not work depending on the OS involved. I wouldn't risk it.
If you want to do a specific net, just take the netmast and XOR it. i.e. a netmask is always 111111...00000 (a string of 1s followed by 0s). The broadcast address is always 000...111. You then have to convert this to xxx.xxx.xxx.xxx notation; if you don't know how to do that, you'll have to look it up anyway (basically, each of the four numbers is a value from 0 to (2^8 -1); it is the decimal version of 8 bits of the number. So, if the first 8 bits are all 1, then the first decimal number is 2 ^ 8 -1 = 255)
2. if a pc has more than 1 network cards, e.g. 1 for the lan, and another for the internet, it has 3 ip's. 2x local, 1x online.
how to find out every ip ? Inetaddress.getLocalHost(), getAllbyName("localhost") etc. just gives me the online-ip...
Just look at the java.net.NetworkInterface class...it's pretty obvious when you look at the method names!