aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes Socket connection on AWS server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Socket connection on AWS server" Watch "Socket connection on AWS server" New topic
Author

Socket connection on AWS server

Archana Jain
Greenhorn

Joined: Nov 03, 2013
Posts: 11
Hi,

I am creating a server & client in java where client is an applet but it is not connecting when I run it on AWS server.

The server code is:-

import java.io.*;
import java.util.*;
import java.net.*;
public class TestServer {

public void process() throws Exception {
ServerSocket server = new ServerSocket(1002,10);
String ia= InetAddress.getLocalHost().getHostName();
System.out.println("Address is "+ia);
System.out.println("Test server Started...");
while( true) {
Socket client = server.accept();
System.out.println("Connected");
}
}
public static void main(String ... args) throws Exception {
new TestServer().process();
}
}

And the client code is:-

import javax.swing.*;
import java.applet.Applet;
import java.io.*;
import java.net.*;
public class TestClient extends JApplet {

public void init()
{
String servername = "ip-172-31-3-228";
Socket client;
ShowMessage("Starting 9");
try
{
client = new Socket(servername,1002);
ShowMessage("Test Server connected");
}catch(Exception e) {
ShowMessage("Test Server is down");
}
}
public void ShowMessage(String message) {
JOptionPane.showMessageDialog(null, message, "Message",
+JOptionPane.INFORMATION_MESSAGE);}
}


I am always getting Test Server is down message. Can anybody please help me?

Thanks in advance
Archana
Karthik Shiraly
Ranch Hand

Joined: Apr 04, 2009
Posts: 539
    
    7
#1. "ip-172-31-3-228" is probably the wrong host. It looks like it's the *internal* DNS hostname, but what you want to use is the *external* DNS hostname or the elastic IP of machine (if one is assigned).
You can get the external DNS name from AWS management console, and it'll look typically like "ec2-xx-xx-xx-xx.compute-x.amazonaws.com".

#2. Check if you have enabled firewall access to port 1002 from the AWS management console's "Security Groups" page. Unless you have enabled inbound traffic to that port, AWS will block it.

#3. If it still doesn't work after these 2 changes, it may be the client side firewall blocking access, especially if you're behind a corporate firewall. To check whether that's the case, try your applet over your home network or a mobile data network.
Archana Jain
Greenhorn

Joined: Nov 03, 2013
Posts: 11
Hi Karthik,

Thanks for the reply. I tried the first two options but still I am not successful in getting the connection. The third option does not apply to my case because in my laptop there is no firewall setting. If it is the security that is blocking the connection then I changed my java.policy file also still I am unsuccessful.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42918
    
  68
Printing some message of your own for all exceptions is not very useful - print the entire stack trace, so that you'll know what the actual problem is.
Karthik Shiraly
Ranch Hand

Joined: Apr 04, 2009
Posts: 539
    
    7
Yes, what does the exception stack trace say?

What OS is on your EC2 server? The OS may have its own firewall activated (typically Windows firewall if it's Windows OS, and iptables rules if it's Linux). Check if these are activated.

What is the inbound rule you added to EC2 security groups?

On client side, if you are accessing all this from your company network, then the entire company's network will have a corporate firewall that usually blocks such arbitrary socket connections from/to all machines in your network.
It need not necessarily be installed on your laptop and java.policy will have no effect, since the blockage is happening external to your device.
Archana Jain
Greenhorn

Joined: Nov 03, 2013
Posts: 11
Hi Karthik,

I am getting below exception:
java.net.ConnectException:Connection timed out:connect

EC2 has linus OS. I will check the other firewalls of linux.
Archana Jain
Greenhorn

Joined: Nov 03, 2013
Posts: 11
Thanks you so much for your help. I got the connection and the issue is resolved. Thanks again
Archana
Karthik Shiraly
Ranch Hand

Joined: Apr 04, 2009
Posts: 539
    
    7
Glad to know your problem is solved!
Perhaps you can briefly describe what exactly was the problem and what you did to solve it, so that it'll help anybody else who has the same problem in future and comes across this thread.
Archana Jain
Greenhorn

Joined: Nov 03, 2013
Posts: 11
Yesterday I changed the security group by adding a new rule, but forgot to apply the security rule changes. That is why it was not working yesterday.
Karthik Shiraly
Ranch Hand

Joined: Apr 04, 2009
Posts: 539
    
    7
I too noticed the weird positioning of that Save button yesterday - it's easy to miss unless one scrolls down. Hopefully they'll improve the usability of their redesigned console. Anyway, thanks for explaining the problem!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Socket connection on AWS server