Share my local webapp project - java

I have started doing work with spring/hibernate to make webapps with java. I have made a basic app which is running on my localhost:8080 and I was wondering if there was an easy way to make it visible to someone else so they can see and use the webpage from their machine.

If They are on same network (ie a Home Network or Corporate Network) you just need to send them you ip and port (ie http://192.168.0.150:8080).
If you want to open your computer by the internet you need to setup you modem to open you 8080 port and need to discover you public IP ou contract a DDNS, like no-ip.
Maybe you can need to change some firewall configurations

If you don't want to configure firewall, port forward. you can try some dynamic dns service like www.no-ip.com, dyn, duck dns, freedns etc.
they will create a public url which will forward.
however at application level you may still need to configure the access permission like white list ip or address to listen
Can't access Tomcat using IP address

Related

Can I access my application running on localhost:8080 from WAN..?

I developed an application in my home machine. Now I want to show application that i made to client through WAN. I have TP-Link WiFi router at my home. Is it possible using port forwarding or other solution ?
Yes, you can use port forwarding to make your application accessible from the Internet. Essentially, what you want to do is redirect traffic coming into your public IP on port 80 to the internal machine running tomcat on port 8080.
There are public guides available for configuring port forwarding on different routers.
Edit: Port forwarding however might not be the only problem. There are other things to consider:
1. You should use a static external IP and map it to a DNS name, so users will be able to access the site by typing the name in the address bar.
2. You should make sure that the machine running tomcat allows external connections to port 8080, so these aren't blocked by the firewall.

RESTful web applications using WAN IP instead of localhost

I am developing a web application in Java by using RESTful web services and Tomcat. So far I was using the localhost in the URI: http://localhost:8080/3.ServerAPI/rest/Variable. But what if I want to use the real IP?
I have tried that on a local network by replacing the localhost with the LAN IP and it works fine: http://192.168.1.2:8080/3.ServerAPI/rest/Variable
The application at this address received the Variable.
If I want to send this through the internet as long as I know I have to use the WAN IP: http://188.39.25.247:8080/3.ServerAPI/rest/Variable
My question is, if I use the last URI with the WAN IP do I need also to port forward to the LAN IP by configuring the router or it is going to work like when I used the LAN IP ??
Thanks in advance
It depends on your network setup really.
You may have to enable port forwarding on your router to direct the request to the machine that your server is on, also make sure that the router allows connections to port 8080.
I had to do this recently when working with callbacks on external APIs. Seem to remember that I had to enable port forwarding on my router to get it to work. Wasn't too difficult though, just check router instructions on how to do it - like I say, depends on network setup though.
Hope this helps.
I've seen something similar to this and the problem was due to the port being used by another application.

Use local pc as a server

I just made a little chat programm with a server and a client in java. The client needs to connect to the server with the ip of the server. All my testing I did with the localhost (127.0.0.1) and everything went fine, but when I tested it later on with a friend of mine, I had to notice that if I put my ip address (I run the server, he runs the client) that it doesn't work.
Is there a way to set up a private little server on my pc to run my server on, or maybe another way to get it working?
EDIT:
Just found a tool called "Apache" to set up your own server, could that might be helpful?
EDIT: When I say it doesnt work I mean I get an IOException, because this fails:
public void connectToServer() throws IOException{
showMessage("Attemption to connect...");
connection = new Socket(InetAddress.getByName(serverIP), 6789);
showMessage("\nConnected to: " + connection.getInetAddress().getHostName());
}
There is a whole host of things that you need to look at before your application will work.
Firewalls on both ends (and anti-virus applications) need to allow
the programs to communicate
Your ISP needs to allow messages to be sent via your designated ports
Your router (and the clients) need to not-filter these messages.
As a start, see if you can ping each others IP addresses and take it from there.
I recommend you first try and disable your firewall. If you are using windows, here is the instruction for turning off windows firewall: Turn Windows Firewall on or off
If you are testing with someone outside of your local network, you may need to setup NAT on the router of the person hosting the server. You can access the router by typing in it's local IP address in the web browser. This is usually something like 192.168.1.1 or 192.168.1.254 but it will depend on the model and network setup.
Once you have connected you should find an option (usually under advanced) for "NAT" or "Port Forwarding". I suggest you do a google search with the router model and how to setup port forwarding.
You also need to be aware that some ISPs will block certain ports. I suggest testing on a common port such as port 80 (HTTP) since it's unlikely an ISP will block this (be aware that you will need to disable Skype or any local web servers to test this)

Java program without forward port in router

I made application with java using socket. My computer is the server and my phone(android ) is the client. Only what i trying to do is to forward String from phone to client PC.
Everything works fine when i configure my router and open the port i using. i don't want every time when costumer will install my application will need to open port in the router.
I thought about using remote server that will run my server code. but i didn't find server that can do that . i don't want to make my pc a server for all costumers.
How does all the chats companies do it without open port?
You must look into UPnP. This is what /most/ if not /all/ torrent clients use to allow foreign connections, without forwarding ports. How chat clients do it is a different scenario. They use hacks such as firewall hole-punching using UDP (with an external server) http://www.h-online.com/security/features/How-Skype-Co-get-round-firewalls-747197.html see this link for details on UDP hole punching.
Also see this article http://www.codeproject.com/Articles/13285/Using-UPnP-for-Programmatic-Port-Forwardings-and-N for usage of UPnP. But this is in C++, but I think you will understand.
EDIT: http://4thline.org/projects/cling/ I found this. I think it can help you.
You had to open port probably because of your routers firewall :). If you already opened let us say port 9090 then every client app (android phone) will be able to connect to it :). Of course if somebody wants to install server on their own pc they would problably forward some ports and disable some firewalls. If you want server with no special requriements lookup VPS'es. :)

Whats my hostname on my local MySQL server?

I just set up a MySQL server on my PC for testing Java with JDBC.
At the moment "localhost" works perfectly as hostname for my applications, when running them on the same system.
However what would be the hostname for my MySQL server for applications that are running on different computers? Something like "my_ip:port" would work? I was thinking of writing an applet, which I could upload on a web server and try to connect to my database here. Is it possible to achieve that?
Something like "my_ip:port" would work?
If the MySQL instance has bound to your public interface, and if your firewall allows it, yes. If you connect to the 'net via a router that does NAT (for instance, a combined DSL modem and wireless router allowing you to connect multiple computers), you'll have to set up forwarding rules in the router to tell it which of the local machines to forward requests to.
You don't have to use an IP address. Your machine will also probably have a host name of some kind (either one you've assigned or, if you connect through an ISP, more likely one they've assigned). That would work too.
I was thinking of writing an applet, which I could upload on a web server and try to connect to my database here. Is it possible to achieve that?
With a signed Java applet, yes; otherwise, no. That's because the security sandbox that Java applets run in doesn't let them access servers other than the one they were loaded from (the web server).
A much better approach is to have your client-side code (Java applet, or just DHTML+Ajax stuff) talk to server-side code on the web server, which in turn talks to your DB. That way, the DB is never directly exposed to the outside world, and you don't have to do things like signed applets.
You can always use the ip address of the server running mysql as the hostname or its fully qualified domain name.
That should work, but you also should consider port-forwarding through your firewall.
Go here to get your IP: http://www.whatsmyip.org/
The port is the port mysql is setup on.

Categories