Submit server IP from wifi router to Android - java

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.

Related

How to find specific desktop's ip address on network?

I'm coding an app which consist of two pieces. Desktop and android. There is one desktop and several android devices. (don't know the count.) I want to communicate android devices between desktop with TCP. However, android devices doesn't know desktop's lan ip address.
I thouht 2 ways:
1-Desktop app changes the local ip address on start. So android devices know the ip address. (I coded with that ip address)
2-Desktop app always tries to connect ip addresses (192.168.0.1 - 192.168.0.255) to sent desktop's ip address. And when an android device connect to the network accept the connection then know desktop's ip.
But there is some problems in both ways.
On first, you must be administrator to changing lan ip. So run command as admin with java is a problem. Because if I do this, when user start the program, uac always asks for it.
On second, I think there will be performance issues because of app always tries to connect. Exept this, when android device connect and dhcp gives it 192.168.0.5 , but loop is on 192.168.0.150. So android device have to wait for connection.
Is there a better way than these?
Look at this post Network discovery in Java using multicasting
I think this would be the best way to do it.
The server will listen for a broadcast message from client
the client sends a broadcast request asking for server ip
server receives request and replies back with server ip.
You can use the hostname. If the network is properly configured, the host name will point to the correct ip even if it changes

How to get local ip address of UDP packet sender in java

I have coded a ip to ip video chat application using JMF for my brothers school project. In which first of all one of the user sends an udp as a chat request to another system. Then the second system sends a reply to the first system after that video chat starts. Every thing is working perfectly while there is no router b/W two systems(e.g. Both are on same lan or connected to internet via usb modem). else when i retrieve the sender's ip from UDP packet it gives the ip of router through which the sender is connected to internet so when second system replies to the request of chatting the first system never receives the reply. So how can i get the local ip of the UDP sender.
Thanks every one in advance.
You're talking about NAT traversal and it's a really hard problem. There's more on Wikipedia https://en.wikipedia.org/wiki/NAT_traversal.
If it's just for a school project, I would just make it work on a local network and not bother with NAT traversal.

Locating IP on network

I have searched the web for this with no success.
This is my problem: I am developing an app that reads data from arduino connected with Ethernet shield.
I can connect to it on the internal network (home network) or through the Internet.
The problem is I need to know if the arduino is present on the local network and if not then look for it on the external ip address.
I have tried to use the ping function but it’s not working. Any help would be appreciated.
I presume you know the IP address of the arduino?, have you tried putting your pc\laptop onto the same subnet as the device, e.g. if the arduino has an IP address of 10.254.103.20 you could change the IP of your laptop\pc to 10.254.103.21 and then try pinging it?
Well for one thing, if your router supports NAT loopback (most do, but you may have to enable it) you can always just connect to the external IP address, regardless of whether you're on LAN or WAN.
Cheers,

How to "deploy" a server so that it can be reached over the internet?

I recently developed an Android application with which the Android device can communicate with another Android device running the application.
The communication works over sockets, therefore I developed a server which i run on my computer.
Here is my problem:
The communication between the devices over the Server running on my PC works fine, as long as all devices as well as the PC are in the same LAN (connected over the same Router for example).
Now I want to get the server online, so that the Android devices can connect to the "online" server and communicate with each other over the server from anywhere.
I simply have no idea of how to get the server online and running. How can I do that?
The main issue is, that I know about Client/Server communication locally, but have no experience in the "online" sector.
It is more a network problem than a programming one. Your server open a socket and therefore is available to anyone able to reach that socket.
You have to do a redirection on your router. The problem is that your machine doesn't have a public IP, only your router has one. So when your router receive a packet on port 21 for example, it doesn't know what to do with it. You have to configure it to say "the port 21 has to redirected to the local IP XXX"
Also the public IP of your modem/router can change, depending on your ISP. If your have a fixed IP, it won't change, otherwise you will have to install a software like dyndns to have a domain name associated with your IP.

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.

Categories

Resources