I created an Android/Desktop game which supports multiplayer on a local area network. I am using DatagramPackets and right now I have hard coded 2 local IP addresses for testing purposes.
How do I make it so when one device is hosting a game anyone else running the game can detect that hosted game on the LAN. Basically I need to get the Local IP Address of the person who is hosting my game from another device connected to the same router searching for a game on the network.
This is how I am currently detecting the other devices on the network by hard coding the address.
outgoingPacket.setAddress(InetAddress.getByName("192.168.1.20"));
I imagine I should be using a broadcast of some sort.
I suspect that you're looking for a more generic broadcast capability that's described here.
Multicast is a whole other kettle of fish!
I think that the best way to do this is to use 1 specific port for the games, and see if someone is online on that port in the network.
Related
I'm developing a Java application which should listen on specific port on computer using Sockets.
The another app, which will run on Android device connected to the same WiFi, should find this computer with my Java program.
How can I find the computer in the network?
I've tried it in the small LAN (where are all devices connected to 192.168.*.*) using InetAddress.getByName(ipAddress).isReachable(); but in the bigger network (like eduroam or my school WiFi) I'm not able to scan whole network.
Is there another option how to connect two devices to each other apart from using Sockets and scanning whole network?
I'm not sure I understand your entire system requirements, but I'm thinking you could create a very small database at a hosting site (such as this) and have your PC periodically upload its private IP address to that database.
Then, when you need to connect to the PC on your android device, you query the database and determine the PC's current address, then connect to the device.
I have to design an app in android for voice over WiFi communication for my university. Our university's infrastructure consists of interconnected LAN's(interconnection between multiple routers at different hostels and classrooms) and also a few wireless access point(all having wired interconnection). The speed of the university LAN is around 100Mbps. What I need my app to do is discover via broadcasting other instances of the app running in various devices within the campus(same android app will be installed on all devices),both within the same subnet(router) and also devices connected to other routers within the campus. The ultimate goal is to also enable end users who connect their phones using connectify me to their laptops to be able to communicate with each other,provided both the laptops are connected to the university network(may not share same subnet).However, even if that is not posible, atleast two devices residing on two different subnets must be able to discover each other. Thereafter, voice calls can be made from one device to another. The idea for discovery is via broadcast messages. There would be no central server. I am new to network programming and also android programming(though I have prior knowledge of core java). Kindly help with the procedure to broadcast messages across my university network for the initial device discovery stage and also suggest any protocols that I need to learn and any codecs for conversion from voice to data. Any other help regarding design and implementation would also be welcomed with gratitude. Please reply as soon as possible.
Broadcast does not cross subnets. For instance pinging 255.255.255.255 on a class C network is the same as pinging A.B.C.255 with A.B.C being the first 3 Octets of your IP address.
Since you mentioned
broadcast messages across my university network
I believe you want to reach destinations beyond your own subnet. You could do so by using DHCP , which would use the routers as a relay agent to forward broadcasts to different subnets. However, I would rather use Multicast as eee mentioned earlier.
I am writing a platform game, and i thought it would be cool to add a multi-player mode for people who are playing on the same network. My question is how would i query through all the available computers open on a certain port for connecting to play multi-player, and then how would i establish a connection with them. I thought i could just create a socket and just try to connect on every port, but how would i do that if i dont know the other computer ip address. On google i saw this question get asked several times, however none of the answers actually seemed helpful.
You will propably want to broadcast a message (broadcasts are received by all devices on the network). Then you would have the other machines listening fir such incoming broadcasts.
Basically in a broadcast you would advertise that a computer is running the program, and is willing to establish a direct connection. Then one of the computers would connect straight to the other, and you would work on from there.
EDIT: Someones similarily done aproach in java (blog post)
I have written a variety of network programmes such as chats and games, but the user always had to enter the ip of the server, which is very unusual.
I want to realize a server browser you may know from common games, which locates servers in the lan automatically. I want to do it in Java.
My questions are:
How does that browsing work? Also WiFi for example, just everything which automatically finds another party.
Would it be possible and also a good approach to broadcast status packages to whole lan all the time? Which time intervals would be useful?
For WiFi, the device listens to a certain frequency range and scans the range for signals. This is much the same process as a TV uses to pick-up stations, or a person might do to find local radio stations.
For an internet game server, you can't scan the entire internet. Normally the services provides a master server which is configured to send the list of servers on a known port. Typically it will also allow servers to update their information as well.
For a local game server, typically it's single packet every few seconds or so. There's actually quite a lot of traffic even on an idle network with various services requesting this sort of data (Apple's discovery protocol, Bonjour is commonly seen, as is the Windows network discovery protocol).
For internet games, there is a central set of servers that host the information needed to a set up a game. In the past, this is typically just the IP address and port of the person hosting the game, as well as any game information, such as the name, map, etc.
These days due to firewall/NAT issues and problems with cheating, most internet games actually send their data through those servers as well. This is expensive to do.
For games on your local network, UDP packets are sent to the broadcast address, which are received by all devices on that subnet. The hosting game sends the packet with information on where to connect, and those joining in receive those packets to know where the game server is. They then connect directly to the game server.
If you are on an IP network and your address is 192.168.1.100 with a subnet mask of 255.255.255.0, then your broadcast IP address is 192.168.1.255. See also: http://en.wikipedia.org/wiki/Broadcast_address#IP_networking
I am trying to control a Remote Control Car with an Andriod Phone from my PC (over 3g internet)
I'm planning on using a ioio (Which is just a board that I can plug into a andriod phone via USB)
The part I am working on now is the communication from my PC to my Andriod App. I've never made Andriod apps before and I'm a amateur C# developer.
At the moment I am planning on communicating via UDP as I can create a UDP server/client in Java easy enough. (http://systembash.com/content/a-simple-java-udp-server-and-udp-client/)
However I think this may require a public IP address? Which I will not have either on my client or server.
So for simplicty sake, How would you commucicate over the internet between 2 JAVA applications. If you need to stream video from a camera and simple commands.
You don't necessarily need a public IP, you just need some sort of IP with which one device can send packets to the other. For example, you could connect the phone to your home wifi network, and use the private IPs (typically 192.168.1.x) of the two devices.
If you need the phone to be on 3G, and your PC is behind a NAT router (which is typical), then you'll need to forward a port to your PC — this is a configuration setting on the router — and then have the phone connect to that port on your router's public IP.