Hosting a web service(Netbeans) - java

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).

Related

Is there a way to connect two computers with a two-way connection on different networks (one has port forwarding)

I am trying to make a two-way instant messaging app over two different networks. One of these networks is mine, which has port forwarding enabled(sends traffic on certain port to specific ip address). My problem is that I need a two way connection(sockets can only send to serverSockets, serverSockets can't send to sockets). Is there a way to connect to a computer via a pre-existing connection? Is there a library for this? ie. socket.connect(serverSocket.getConnection, 5001); (I have made my own classes which handle all the Input/Output Streams and sockets, I just need a library for a function I can put in the class).
If what you're asking for is to have a computer exposed to the internet to directly connect to a computer behind a NAT, you might get your app working if you are able to implement something similar to reverse ssh tunneling. See here and here, for a java library.
But I would recommend some sort of client-server approach for this, in which everyone connects to the server, and through the server they connect to each other.

How can I use java sockets to communicate between different networks?

I have java programs for my client and server, and they work fine within the same wifi network. But I need the clients to be able to connect to the server from the open internet. In questions like these
How to connect client and server with the help of ip address which are connected to internet through different wifi?
https://coderanch.com/t/667020/java/Socket-connections-networks
the solution is to manually reroute a port to the server from the router, making it open to connections from the outside. Is there a way to do this with just software on the server? I don't understand why manually dedicating ports is necessary since of course other applications on my computer (like games) that I install communicate with their servers back and forth without me having to manually go in and flip switches.
How can I achieve this with just software running on my server?
If there isn't another way, how do other applications communicate openly without manual router changes, and will opening up ports through my router result in security issues?
You would need to change the architecture of your application. Currently, your server is behind a firewall which blocks connections from the internet - you want this! If you allowed all traffic from the internet to connect indiscriminately to your server, it would be very vulnerable to attack.
Other applications install and communicate without port-forwarding because the developer provides a server on the internet to act as a proxy between clients. The client connects out to the internet which is generally not blocked on home networks. Internal connections going out are considered less harmful than connections coming in.

Add Java API to online server not localhost

I have just created a Hello World RESTful Java API with IntelliJ IDEA and Spring and I make several requests with http://localhost:8080/function and it works fine and return the JSON data well, but now I want to make request from my android app to get the same JSON data from another network. How to create global API or make my local API global or online?
If it is working on your PC, your next step is to host it somewhere which is reachable from the outside world. If it is still in testing mode, probably what you need to do is port-forwarding from your router, so that your requests to your public IP get forwarded to your PC.
In the long term of course you need to host it somewhere, unless you want to leave your PC running. You can buy a cheap hosting to start with on something like Digital Ocean, or go for the more advanced cloud service providers like Google and AWS.
in your router you have to redirect port 8080 to you network IP and allow port 8080 in your firewall
And use this IP address https://whatismyip.com.br/
You can create your java application in a container and deploy it on one of the cloud providers (AWS, Azure, Google App Engine).

Android Port scanning for TCP server?

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.

Accessing a Java Web Application via Mobile

I have a basic web application written in Java, running on a tomcat on my localhost. Currently it's just a simple application with a single servlet to which I access from my browser.
I want to write a mobile android application which will be the client of my Java web application. I want the servlet to write to a DB and do some logic, but to access it from a mobile app.
Currently I don't have any domain registered.
How can I expose my Java web app so that in my development environment I would be able to access it via my mobile device? Meaning, currently it runs locally on my PC and I access from the browser (on localhost). I want to access it from a different device (mobile) - how can it be done in my home LAN?
Thanks.
If the web app is hosted on your local server, your mobile will need to be able to access the IP address (ie: 192.168.1.100) and port (ie: 8080) that is hosting the app.
There are several ways to allow your mobile to communicate to your desktop:
Direct connection via USB or Bluetooth.
Wireless connection on your LAN - if your mobile can connect
wirelessly to your home LAN, you should be able to access your web
app (your desktop's firewall may have to open up your web port)
External access. This requires opening up your home network to allow
access to your desktop's web port. Also your internet router would
have to be configured to allow access and likely do a NAT
translation. Note that in this scenario, anybody can access your web
app so be very careful. You would also need to use your external IP
address instead of your internal LAN address.
A domain is only required to allow the use of a name (http://www.example.com) instead of your IP address.
For testing, if your mobile device is on the same LAN as your server, just use the servers ip address on the LAN. Give the server a static ip address and your sorted.
For the next stage of testing, you'd need to expose your pc to access via the Internet. You'd usually do this by configuring your NAT settings on your home router. You should be able to google this.
Then your mobile device can use 3G and should talk to the server via your ISP ip address. This will hit your router and the NAT routing will forward it to your server machine on your LAN.
If you need any clarification, just ask !

Categories

Resources