Find an application running on a network - java

I'm new to networking and was wondering a way to find out from an android phone java app whether there is an application running on any computer on a wifi network it's connected to and a point in the right direction on what to google or a tutorial?
edit: The application I'd be finding would have been made to be found by the android app
Thanks,
Harold

You should use a UDP broadcast. Basically, a server announces its presence periodically on a local network with broadcast packets. A client then picks up on these packets, finds the source and connects to it. A networking library like KryoNet (available for both J2SE and Android Java) makes it much easier.
InetAddress address = client.discoverHost(54777, 5000);
System.out.println(address);

usually application discover their peers in the same network using UDP broadcasts, maybe thats what you are looking for. this requires the app on the lan to listen on a specified port, the phone (or whoever is looking for that app) sends a udp packet to that port on the broadcast address (255.255.255.255), and the app replies with its individual ip address. not sure if that is what you are looking for and if its possible with android

Related

How to send data over public IP?

I am currently working on an Android app that needs to transmit data from one device to an other. I want to implement the data transmission without any server. I can handle the handshake to exchange the dynamic IPs on my own (Session Initiation) but I am struggling for weeks now how to send the data to the other device when knowing their public and private IP.
For now my app can just send data with TCP Sockets to devices within the same WiFi (so just using private IP). But they will get lost once I try to send to public IPs. Probably they can't pass the router's firewall. Turning off the firewall manually is no option. So I guess TCP is the wrong protocol. I think of something like "Voice over IP" but with sending any binary data instead of just video and audio.
My Ideas were:
something like Magic-Wormhole because it works like a charm on PC but unfortunately I did not find any way to use it in Android
RTP (Protocol used for Voice over IP)
"UDP hole punching" to handle the NAT.
One of those might be the solution. The problem is that I don't know how to implement such things in Java/Android
(my Project on GitHub)
Currently the internet is really complicated, basically you cannot reach another device by send data to its public IP because most PC or mobile device are behind a NAT.
What you need in such cases is a STUN server, the server can help two devices to communicate to each other in complicated networks. You can create your own STUN server by using open source implementation like STUNTMAN, but its really complicated, so my suggestion is just try a commercial STUN service.
You can check out the Google STUN server for RTP/UDP packet transmission to the network.
STUN servers: A Quick Start Guide
Port URI
STUN Server (Main LB) 19302 stun.l.google.com
STUN Server 19302 stun1.l.google.com
STUN Server 19302 stun2.l.google.com
STUN Server 19302 stun3.l.google.com
STUN Server 19302 stun4.l.google.com

Accessing android app through TCP/IP by PC connected to android hotspot

I'm creating an Android app which is Mod-Bus TCP slave simulator and I have a problem when trying to connect from pc to it while sharing a connection via wifi hotspot.
I tried using gateway IP but it does not work. When phone and pc are connected to the same wifi (other than themselves) everything is working fine but I need to make it also work with hotspot running and pc connected to it. Is it possible? How?
App is using modbus4j lib.
Actually, I don't think so that Modbus TCP works on mobile hotspot too because recently when i was working on MB TCP I found this. I tried to connect with the ip and gateway of my mobile hotspot but it didn't work this could happen because our mobile hotspot works on DHCP so the gateway is not static. But Modbus TCP works very fine on Wifi router ip and gateway.
Your problem has nothing to do with java or android or Modbus, but it is a problem of understanding how routing works on the internet and on internal networks (your WiFi network is an internal network)
The problem is that the ports waiting for connections on the internal network, like your android device, are not accessible from the internet.
To make them accessible, one or more NAT rules must be defined in the WiFi router. But this will only work if your internet provider assigns you a public IP, which is less and less frequent due to the shortage of public IPs.

SSDP Device Discovery for Application in Java

I have some hardware devices connected to a specific network and I have a Java application also running in the same network. I now need to detect these devices from my Java application. The specification is like this:
My Java program has to send a UDP packet with a host name
{"type":"HW-PROBER","hostname":"Host-NAME"}
The hardware upon receipt of this message sends me back a response with the NOTIFICATION in the form of a Payload that looks like this:
{"type":"HW-NOTIFY","hostname":"Host-NAME","ip":"1.2.3.4"}
So this way, my Java application has to get the ip address of the hardware and start communicating with it. I'm totally unclear on how to do the device discovery. Would this mean that my Java application has to open a port say at 5000 (for example.,) and keep waiting for packets? What sort of API from the Java standard library should I be using?

Communicate over network without knowing device IP address

I am working on design of a device that are installed on clients networks. Currently there is about 180 devices installed arround the world. One major concern is to access them for debugging purpose later.
Context :
All devices work the same.
OS is Linux
Default mode is DHCP but sometimes Static IP
Currently the method to get addresses is :
Log on a computer of the client with any remote desktop software available and search with :
DHCP address in router's leases table (most of the time clients doesn't know their credentials)
Angry IP scanner, scan for port 22 (slow)
ping the name of the device (doesn't always work)
Expecting :
Actually I know it is possible to communicate with devices on network without knowing its IP address by broadcasting on the network but not found any example yet or start point. I would like to write a small Java program that will be able to broadcast on a network to :
List every devices with their IP
Assign IP address to device and/or other functions
Remember : I would like to find devices that have no keyboard, screen or other UI. If I receive a unit from a client (for debug purposes) that was configurated for example with 10.1.1.100 and my computer is on 192.168.1.110 (on the same switch), I want to be able first to know the IP address of this device, second, be able to send a SET IP command (I'll manage how to handle it once I'm able to send data).
For the server part of the device, I don't mind, it could be done in C++ or script... This will probably needed to answer to broadcast and receive requests.
So far, I've been able to create a small UDP client and server.
Client in Java using DatagramSocket, server in C using recvfrom().
The problem with this solution is that my computer need to have the same network mask as the device, example :
Device has 192.168.2.217
Computer has 192.168.1.110
My computer will need 255.255.0.0 as netmask, ortherwise I will not be able to broadcast 192.168.255.255.
Seaching more, the need to change the local computer netmask to meed broadcasting range seems to be a limitation of Java...
new DatagramPacket(sendData, sendData.length, InetAddress.getByName("255.255.255.255"), PORT); // not working
new DatagramPacket(sendData, sendData.length, InetAddress.getByName("192.168.255.255"), PORT); // working only if netmask is 255.255.0.0
I think I will need to go deeper in network protocols to do it the way I want and that I know it is possible.

How should I go about implementing this SMS notification system?

I have developed a application which involves billing users. To do this i have incorporated a GSM modem (gateway) that the SMS messages are sent through. This SMS message is sent to the user when he is billed with the bill details. The GSM modem is connected to a single computer but the billing can happen in other systems. How do I send an SMS notification for the changes that occur in the other systems, as the GSM modem is attached to a COM port on the computer*.
can we access the COM port of other system or shoould i use socket programming (with the machine with the modem(Server) listening for any connection, the sender has to send data in particular format and the server has to parse the data and send the message) or use Java RMI or is there any other solution.
Suggestions please....
Thank you
There are any number of solutions you can think up. The most common ones would be:
Communication with some kind of RPC, be it RMI, SOAP, plain HTTP, telnet, etc.
Using an SMS gateway such as Nordic Messaging’s EMG (probably overkill, though) or kannel (seems to be down currently).
We've got an SMS Gatway. We wrapped it in a J2EE-application with a webservice interface. That way we can send SMS from any of our applications. For the sake of java we made a little jar-file that talks to the webservice
SmsClient smsclient = new SmsClient();
smsclient.sendSms(from, to, message);
I built a similar system to this in the past where small embedded systems sat on a network and reported messages over the network to a central server that logged the messages and sent SMS messages when required.
I used a java socket listener that waited for UDP messages from the embedded units and the java program wrote to the GSM modem on the servers comm port. UDP was only used instead of TCP as it was simpler to configure on an embedded system.

Categories