Right now I have a Server.java script that is waiting to establish a connection with a listening port. It is currently running on my Amazon instance.
I also have a Client.java file that is trying to send data to the server that is running locally.
Currently the problem is (and if you know about Amazon cloud you know this) the amazon Ubuntu instance requires a private key to confirm the RSA authentication. Is there someway to do this with the socket? I looked at the constructor and could not find anything to give another argument for the key.
to SSH I have to do this i.e. : ssh -i key.pem root@server.amazonaws.com
Client. java
import java.io.PrintWriter;
import java.net.Socket;
class Client {
public static void main(String args[]) {
String data = "toobie ornaught toobie";
try {
Socket skt = new Socket("my ubuntu instance", 1235);
System.out.print("Server has connected!\n");
PrintWriter out = new PrintWriter(skt.getOutputStream(), true);
System.out.print("Sending string: '" + data + "'\n");
out.print(data);
out.close();
skt.close();
} catch (Exception e) {
System.out.print("Whoops! It didn't work!\n");
}
}
}
You are confused. TCP sockets have nothing to do with ssh (except that ssh does use a TCP socket). RSA keys are needed for SSH. You are just opening a plain TCP socket. The keys and other authentication stuff do not apply.
What you need to do is allow your port number through the firewall which is automatically running on EC2 instances.