Android Port scanning for TCP server? - java

I have a TCP server running on a specified port (23232), and an Android app that needs to connect to the IP and Port of this server. Is it possible to obtain the IP by scanning for a port only? I have media player control apps that do this but I have no idea how to implement it.
Thanks in advance.

This is on a local network, correct? I would recommend that you use a multicast service discovery mechanism via UDP, since this is the exact kind of scenario it is intended for. Fixed port, unknown entities on the LAN providing the service.

Related

Public to Local IP Communication

I have created project which has two components as Desktop client and web.
web server is communicating to the my another program which i run as client on other systems.
After connecting those clients communication is happening in network as all IP's within network are reachable.
However, when i deployed web app on public IP now i am not able to connect the clients as the local IP's of those clients are not reachable by server.
How can i achieve this communication between local IP to public and vice versa?
There are multiple ways to achieve this.
Anyways, if you want the service to be reachable publically then you´ll probalby want to forward the Port to the machine running the service.
Also, make sure the Firewall allows connections to this port.
Since you´re talking about Web-Apps it´s probably HTTP, Port 80 TCP, or HTTPS, the encrypted version of HTTP running on port 443 TCP.
To explain it, your ISP gives you one public IP address.
Since you probably have multiple devices using internet, they all appear in the internet as the one IP address your provider gave you.
Whenever you send something out your router will remember where you tried to connect and if a response comes in your router knows which device to send the response to.
Now, since you want someone to connect to you, there was no request so your router does not know where to put the packet and simply blocks it.
In most routers you can configure something usually called NAT or Port Forwarding. You simply specify that communication on Port 80 or 443 should be routed to the internal IP. It has one of the following formats:
192.168.0.1 - 192.168.255.254
172.16.XXX.XXX - 172.31.255.254
10.0.0.0 – 10.255.255.254

Socket communication on Android localhost

I'm developing multiple applications which need to communicate with each other via socket. First I need them to be able to communicate on localhost. So when I'm running both of them at the same time on my phone they can communicate (I know that there are easier ways to do this on the same phone but in the future they will run on separate phones).
My code for socket communication is very similar to this: link
Difference is that my apps are running this as foreground services.
I've set the ip for the server on the client to 127.0.0.1 but they just won't connect (not in the emulator and not on real phone). What am I missing?
UPDATE:
I've found an easy way to get the device own IP address, so instead of localhost I use this (with www.google.com domain): answer to "java InetAddress.getLocalHost(); returns 127.0.0.1 … how to get REAL IP?"
Maybe it's not too nice but it works.
You'll need to set the local IP address of each one, so they can communicate within your LAN. So use an address like 192.168.1.X. Both if you're running your devices as virtual or physical, you may easily know the local IP address they have accessing your router's web interface and seeing their bound IPs.

Java Client-Server connection without port forwarding?

I would like to implement a connection between two devices with Java. Actually I am using ServerSockets and this implies that I have to use port forwarding because I want to connect the computers via public ip addresses. This works fine. But I would like to connect the devices without port forwarding or other changes on the router. Is this possible?
How should I connect the devices? Might be a P2P Connecion the solution?
Thanks in advance.
I would like to connect the devices without port forwarding or other changes on the router. Is this possible?
Yes, don't go through the router. ie. access it on the internal network. If you are using the router, you have to configure it.
How should I connect the devices?
Without more details, I would suggest TCP is the simplest.
Might be a P2P Connecion the solution?
It might.

Hosting a web service(Netbeans)

I have developed a web service using netbeans. It's currently being hosted locally(localhost). I wish to connect to this web service through my android phone(and not the emulator), however when using 3G, no connection takes place.
Is there a way that I could solve this? Thanks!
Local networks usually employ NAT. NAT prevents creating inbound connections, from internet to IPs inside NATed networks.
One way around this is to do port-forwarding on your router (if your router is the one doing the NAT).

How to send TCP queries for unknown IP of embedded system?

I need to make Android application which can send TCP queries to an embedded RS-232 system (connected to a router).
Unfortunately, no IP address was given because each embedded system has a different IP address.
To learn the IP Address, an android device (tablet/smartphone) must connect to the local wireless network and acquire the address of the embedded system. The local network also has a public IP address which enables the embedded system to communicate with the outside world.
My task is to send queries to the embedded system and get replies from it. The protocol is RS-232 for both input and output.
Please, give me an idea of where to start. Thank you.
Scan the network for the open port if there are no zero config options.
If you know the range of mac addresses the devices use you should be able to filter them out using ARP.
In case you can control both ends you can use multicast and save the discovery step.
Alternatively you can use dns-sd, but again the embedded system should be aware of it.
At the end, if none of the above options are possible you should scan the network as mentioned in other answer, but if DHCP is used you will never know if the address you obtained is still valid.
If you are talking about on the same network you could use a UDP broadcast which is picked up by the device which contains the remote ip, which then sends a response to the android handset with it's own tcp ip address.

Categories

Resources