How to host java application in aws? - java

I know its pretty silly question but I am not able to get it done.
I have a simple chat service. 2 java programs. One is client.java and other is server.java. It is developed using sockets. Now I tested it. It works perfectly well in the localhost.
I have created windows server 2012 EC2 instance on AWS and run my server.java through command prompt in window server. But when I am trying to connect to it from my machine via client.java, I am not able to connect to it.
What might be the reason?

AWS instances are usually not accessible from the outside. They are protected by an internal firewall and have private IP addresses. There is a "public" interface but this won't expose any port other than ssh or windows 53 remote access.
In brief: go to management console:
Go to "Elastic IP", get yourself an "elastic IP" and assign that to
your instance. This is the IP address, by which you may reach your
instance.
Go to "Security Groups". Add a new group or take the default. Add a
rule, opening the port of your java application to the public. Don't forget to assign that group to your instance, once you have created a new group.
That should do the trick ...

Related

How do I communicate with a Springboot application on an Azure VM machine?

I have a springboot application running on a Microsoft azure VM machine, which I want to be able to communicate with from the outside world.
When I type in the address to the application in a browser on the VM machine, which in this case is http://localhost:8080/spring, I get the expected reply back.
However, when I try to reach this application from any other device, even when using the public ip address for the virtualmachine, for some reason I cannot access it.
Do anyone of you know what I should do to solve this problem?
You will need to export the port that you want to access externally.
You can find a documentation on how to open ports here, through the Azure portal.
To summarize from their documentation:
Create a Network Security Group (NSG)
Select from the newly created NSG, create a new Inbound security rule
Select HTTP, your port that you desire (in your case 8080), priority 100, give it a name.
Your final step is to associate your NSG with a subnet or a specific network interface.

Java get REAL loopback address programmatically

I am developing a Java application which will listen a local port to communicate with another program. Normally it will listen to, say 127.0.0.1:8808.
One of my client reports that they are using Citrix environment, it is like MS remote desktop environment, multiple users can log in the same machine in the same time.
As you may know, such terminal server users share one loopback address, that means, only the first user run my application can successfully bind to 127.0.0.1:8808, the others will receive resource conflict error.
My client try to fix this by enable "virtual loopback", this setting can automatically assign different loopback address to different users, every user will get 127.0.0.2-127.0.0.255 as the loopback address instead of all 127.0.0.1, that sound like a perfect solution for this situation.
A test shows virtual loopback works well for other programs like chrome and IE, TCPView tool shows any connection to localhost are redirect to 127.0.0.2, except my program.
I am thinking the problem may be because I am using the fixed address 127.0.0.1 in the code, but I don't have an environment to confirm. So my question here is: Is there any Java method I can use to get the REAL loopback address in such situation, so I can bind to the the right address?
Thanks in advance!

Run jsp pages from remote server

I am new to JSP and servlets. I configured my eclipse and am now able to run a helloworld jsp program. Now, i want this to be run on a different system.
Following were my queries.
1) Can i enter the IP of my current system where eclipse and tomcat are installed and running and run the application on the computer 2?
2) If question one is not possible, how can i test my application outside local host without purchasing the server.
Please share your knowledge
If I got you right, option number 1 should work.
You currently have a webapplication running on your local machine. So you can enter something like http://localhost:8080/myapp in your browser and see a webpage from your application.
Next step to replace localhost with an ip adress or computer name. So still on the same computer the following should work: http://192.168.123.1:8080/myapp and http://mycomputer:8080/myapp. Of course I just made the ip address and the computer name up and you have the real values.
These two urls should also work from a remote computer that is on the same network. Like the computer of you coworker, or the second computer in your home network.
Possibly the next step would be to deploy your application on a cloud service. But that is a different story worth its own question.
You can put your app in tomcat directory/webapp.
you have to put there .war file of your application.
Then from firewall add inbound rules that on port 8080 incoming request to all connection.
then from at any place from your intranet just type your ip :8080/app.
look here my answer of same query like you.
it is possible in LAN you just need to put the SERVER IP instead of localhost
example: 192.168.1.23:8080/test
if you want to access it in outside via Internet connection
first you should have STATIC IP it is provided by your internet service provider ask them.
and dont forget to off your firewall or add it to exception

Indirect telnet connection with Java

Scenario
I'm in a Java project where we have to communicate with the CLIs of other machines. Unfortunately, we can't connect to these other machines directly and another bad luck is that they only support telnet. So we have the following setup, which is carved in stone (of course):
application <---- telnet or ssh ----> gateway <---- telnet ----> machine_001
(10.0.0.1) (192.168.1.1) (192.168.2.1)
(192.168.2.2)
( ... )
It's possible to connect via SSH or telnet to the gateway manually (e.g. using PuTTY), telnet from this shell to one of the machines and work with its CLI. As we want the communication to happen automatically, the application must be able to talk to the machines by itself; so I need a programmatic solution.
What I've tried so far
After some research on the internet I've found a library called JSch which looked promising, but I've encountered an evil problem. When the applications connects to the gateway, the telnet command and therefore the whole CLI of the target machine is one single command from application's viewpoint. So I'd have to struggle with a non-terminating InputStream, unsynchronized OutputStream and Threads if necessary.
The next try was to establish a SSH tunnel from L127.0.0.1:1234 to 192.168.2.1:23 (via the gateway), but with this configuration it's not possible to telnet to 127.0.0.1:1234 (neither programmatically nor manually).
The actual question
How can I get my application to talk to the machines via the gateway using telnet?

How can i host java udp program for my android application?

i am developing an android application in which the server side execution is done using a simple java udp program.i want to know how i can host this application because i need a static ip server to run the java program.can i run my java program in a server.is it possible if yes how?
You'll have to write a listener in some language (PHP, Java, Etc.). As for a static ip address, you can also look at a dynamic ip redirection service like no-ip;
http://www.no-ip.com/services/managed_dns/free_dynamic_dns.html
You can use a personal machine thats always online, or you can try to use a shared hosting plan that allows you to have a listening port open. A web service will likely be easier to work with than having some custom UDP/TCP connection.

Categories

Resources