How does a server browser e.g. in games work? - java

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

Related

broadcasting in a LAN/between interconnected LAN's using android

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.

Connecting to lan network

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)

Direct TCP/IP networking between two android devices over internet

Hey I am just a beginner at networking.
Is it possible to connect two android devices to each other using sockets over the Internet without using any intermediate dedicated server, Given that there are Nat routers in the wifi and GPRS/3G connections.
I heard that you need to send a outgoing message to other device first , then only NAT would allow that device to reply back to you. But when both device behind NAT how would the first message or packet reach to anyone of them?
EDIT : Observation-> When i query for location of my public IP address I get random places
like other cities and sometimes other states!!! What's the matter? can anyone explain?
The overall design of such a solution involves the use of a third party server. In order for the clients to connect to each other, their public IP (i.e., the NATs IP) has to be known to the other party. When I had to something similar, I implemented STUN, which is part of the ICE technique for establishing peer-to-peer connections. STUN supports both TCP and UDP-traffic. If you want to understand STUN, you should also read about TURN.
Even though STUN requires the user of a third-party for clients to be able to connect directly, there are many public STUN servers available. Here is one of the lists a quick-google search turned up.

how to send messages using only IP address within LAN

I have two wifi modules that connects to my access point. my android phone connects to the same access point. Is there a way in Java to be able to send a message to any of the clients from my phone using just the IP address. I do not want to run a server on my phone.
I'll appreciate any assistance. Thanks
I feel there is a confusion about IP addresses and servers in general. An IP address is a way to find an entity on the network (it is an address). Since your phone is connected to the same access point, it is (very likely) on the same subnet. What that means is that it can talk to any of the other entities without going through a gateway, that is all.
While it is able to talk to them, there has still to be some entity listening. When your phone sends a message to a particular address (the other node on the network), the packet may make it there, but for the communication to proceed:
There has to be some listener on the other end that picks that incoming message
The communication has to follow a prescribed set of rules (protocol)
From what I gather, your phone is acting as the client, not the server. It initiates communication with the other entity on the network. Depending on which node on the network you are trying to talk to, that node is supposed to be expecting that communication and know how to carry it forward.
If you clarify the setup and your desire, may be you can get more to the point response.
What you were not understanding here is that you can send the message to that device with ip address but that data will not be shown on that device's screen because you didn't provided any port number for a process which is listening on that particular device. Your message will be sent but the device would not know what do with it.

Is it possible to transfer data directly between two android devices to other users in the same network?

Let's say I have two android mobile devices, connected to the same wireless network, and that network hasnt external/internet access.
Without third party software, is it possible to transfer data through wifi without knowing the ip from each other and without creating an hotspot? Something like we do on Windows (if 2 pcs are on same network, they can share information directly without internet access)
Starting with the basics, I would like to develop an application, where android phones on same network appears on a list , and then a user choose on of them and writes something - and if the other user have the same app running, appears that on his phone (and then he can reply of course - basically, a chat.
I know this make no practical sense, but believe makes all the sense for what I need to do (it's not a chat of course). If anyone knows anything, please help me - i found nothing.
Thanks in advance.
If you want to send data or messages from one phone to another using the network you will eventually need the IP address of the recipient phone. However, If you don't care about targeting specific phones you could always send UDP broadcast packets that each device on the network should receive.
If you don't want to manually specify an IP you'll need to create a discovery protocol that a phone uses to discover all the other phones on the network. You could do this buy scanning all available IP addresses and checking to see if they are a valid android phone. Or you could have each phone broadcast its presence on the network using a UDP broadcast packet sent to a predefined port.
Once you have discovered all the phones on the network its really up to you to decide how you want to send the data between phones and there are hundreds of examples of how to send data between devices/computers/processes using sockets.

Categories

Resources