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.
Related
I am trying to build an android application that connects two or more devices as a client/server(using socket).
But problem is in client device user need to manually put IP address of Server device to connect with server. But from the client i don't know the server IP Address. and i don't want to enter it manually.
is there any way to get IP address(programmatically) of server device that using same application and on the same network ?
Any help would be greatly appreciated.
Thank in advanced.
After trying many ways finally, I have got a solution which is
Network discovery using UDP broadcast (credit goes to this documentation)
(Thanks #Fildor for your suggestion to implement this service).
Solution
Using UDP packets and broadcasting them! This technique however is not optimal, but as long as we stay in one network this shouldn’t be a problem.
UDP packets however are fairly easy to work with.
Server implementation
Open a socket on the server that listens to the UDP requests.
Make a loop that handles the UDP requests and responses
Inside the loop, check the received UPD packet to see if it’s valid
Still inside the loop, send a response to the IP and Port of the
received packet
Client implementation
Open a socket on a random port.
Try to broadcast to the default broadcast address (255.255.255.255)
Loop over all the computer’s network interfaces and get their
broadcast addresses
Send the UDP packet inside the loop to the interface’s broadcast
address
Wait for a reply
When we have a reply, check to see if the package is valid
When it’s valid, get the package’s sender IP address; this is the
server’s IP address
CLOSE the socket! We don’t want to leave open random ports on someone
else’s computer
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.
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'm currently writing an app that's to connect to a server over a wireless lan.
So far, I've got the IP address hardcoded into the app (which works perfectly), however, the next logical step is to be able to send the app the server IP address.
From what I understand, the router needs to broadcast the IP address over 255.255.255.255 - apart from that, I have no idea what to do.
Any and all help is greatly appreciated
edit
ok, so I know to get this working, all phones have to be on the same network as the server, which is fine.
What I need to do is get the phone to broadcast on the network whilst my server listens. From there, the server sends the app its IP address, then the rest of the code can continue.
Does anyone have a tutorial or anything I can follow to get both sides working?
one simple solution for you not to hardcode the server's IP or name (let us say it changes over time), would be for you to implement a name server on your network and have the android device call a local URL.
you could then post the current server's IP or name in the header of a web page on your local network. this response would then be used by android app.
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.