Java RMI AWS two machine

Multi tool use
up vote
0
down vote
favorite
I have two machines:
Server: AWS - EC2 - Ubuntu 18.04 Lts
Client: Windows 10
If I try run my code just in AWS machine it's work normally, but if i try same in other machine I have ConnectionRefused by time in Client machine
Code:
AloMundoServidor.java
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.io.*;
public class AloMundoServidor implements AloMundo {
private static int count, fila = 0;
private static boolean lock;
public AloMundoServidor() {}
public String digaAloMundo() throws Exception {
System.out.println("Chamada de aplicacao Cliente recebida! " + count);
/*fila++;
if(lock){
try {
wait();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
//Log.error("Thread interrupted", e);
}
}
lock = true;
*/
File file = new File("test.txt");
BufferedReader reader = new BufferedReader(new FileReader(file));
String text = "", line;
while ((line = reader.readLine()) != null) {
text = text + "n" + line;
}
count++;
Thread.sleep(5000);
// fila--;
// notify();
// if(fila==0) {
// lock = false;
// }
return text;
}
public static void main(String args) {
count = 0;
lock = false;
try {
AloMundoServidor obj = new AloMundoServidor();
AloMundo stub = (AloMundo) UnicastRemoteObject.exportObject(obj, 0);
Registry registry = LocateRegistry.getRegistry();
registry.bind("AloMundo", stub);
System.out.println("Servidor pronto!");
} catch (Exception e) {
System.err.println("Capturando excecao no Servidor: " + e.toString());
e.printStackTrace();
}
}
AluMundoCliente.java:
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class AloMundoCliente {
private AloMundoCliente() {}
public static void main(String args) {
String host = "54.244.xxx.xxx";
try {
Registry registry = LocateRegistry.getRegistry(host);
AloMundo stub = (AloMundo) registry.lookup("AloMundo");
String resposta = stub.digaAloMundo();
System.out.println("resposta: " + resposta);
} catch (Exception e) {
System.err.println("Capturando a exceção no Cliente: " + e.toString());
e.printStackTrace();
}
}
}
AloMundo.java
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface AloMundo extends Remote {
String digaAloMundo() throws Exception;
}
I execute telnet 54.244.xxx.xxx 1099 and its listing.
I tried java AloMundoServidor -Djava.rmi.server.hostname='54.244.xxx.xxx'
And no sucess!
Edit.:Solved
Launch cliente:
java -Djava.security.policy=server.policy AloMundoCliente
Modified ClienteCode in Registry with server IP:
Registry registry = LocateRegistry.getRegistry("xx.xx.xx.xx");
Create server.policy:
grant{
permission java.security.AllPermission;
};
Launch server:
java -Djava.security.policy=server.policy -Djava.rmi.server.hostname=XX.XX.XX.XX AloMundoServer
java windows amazon-web-services amazon-ec2 rmi
New contributor
Lucas Arkantos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
0
down vote
favorite
I have two machines:
Server: AWS - EC2 - Ubuntu 18.04 Lts
Client: Windows 10
If I try run my code just in AWS machine it's work normally, but if i try same in other machine I have ConnectionRefused by time in Client machine
Code:
AloMundoServidor.java
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.io.*;
public class AloMundoServidor implements AloMundo {
private static int count, fila = 0;
private static boolean lock;
public AloMundoServidor() {}
public String digaAloMundo() throws Exception {
System.out.println("Chamada de aplicacao Cliente recebida! " + count);
/*fila++;
if(lock){
try {
wait();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
//Log.error("Thread interrupted", e);
}
}
lock = true;
*/
File file = new File("test.txt");
BufferedReader reader = new BufferedReader(new FileReader(file));
String text = "", line;
while ((line = reader.readLine()) != null) {
text = text + "n" + line;
}
count++;
Thread.sleep(5000);
// fila--;
// notify();
// if(fila==0) {
// lock = false;
// }
return text;
}
public static void main(String args) {
count = 0;
lock = false;
try {
AloMundoServidor obj = new AloMundoServidor();
AloMundo stub = (AloMundo) UnicastRemoteObject.exportObject(obj, 0);
Registry registry = LocateRegistry.getRegistry();
registry.bind("AloMundo", stub);
System.out.println("Servidor pronto!");
} catch (Exception e) {
System.err.println("Capturando excecao no Servidor: " + e.toString());
e.printStackTrace();
}
}
AluMundoCliente.java:
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class AloMundoCliente {
private AloMundoCliente() {}
public static void main(String args) {
String host = "54.244.xxx.xxx";
try {
Registry registry = LocateRegistry.getRegistry(host);
AloMundo stub = (AloMundo) registry.lookup("AloMundo");
String resposta = stub.digaAloMundo();
System.out.println("resposta: " + resposta);
} catch (Exception e) {
System.err.println("Capturando a exceção no Cliente: " + e.toString());
e.printStackTrace();
}
}
}
AloMundo.java
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface AloMundo extends Remote {
String digaAloMundo() throws Exception;
}
I execute telnet 54.244.xxx.xxx 1099 and its listing.
I tried java AloMundoServidor -Djava.rmi.server.hostname='54.244.xxx.xxx'
And no sucess!
Edit.:Solved
Launch cliente:
java -Djava.security.policy=server.policy AloMundoCliente
Modified ClienteCode in Registry with server IP:
Registry registry = LocateRegistry.getRegistry("xx.xx.xx.xx");
Create server.policy:
grant{
permission java.security.AllPermission;
};
Launch server:
java -Djava.security.policy=server.policy -Djava.rmi.server.hostname=XX.XX.XX.XX AloMundoServer
java windows amazon-web-services amazon-ec2 rmi
New contributor
Lucas Arkantos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have two machines:
Server: AWS - EC2 - Ubuntu 18.04 Lts
Client: Windows 10
If I try run my code just in AWS machine it's work normally, but if i try same in other machine I have ConnectionRefused by time in Client machine
Code:
AloMundoServidor.java
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.io.*;
public class AloMundoServidor implements AloMundo {
private static int count, fila = 0;
private static boolean lock;
public AloMundoServidor() {}
public String digaAloMundo() throws Exception {
System.out.println("Chamada de aplicacao Cliente recebida! " + count);
/*fila++;
if(lock){
try {
wait();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
//Log.error("Thread interrupted", e);
}
}
lock = true;
*/
File file = new File("test.txt");
BufferedReader reader = new BufferedReader(new FileReader(file));
String text = "", line;
while ((line = reader.readLine()) != null) {
text = text + "n" + line;
}
count++;
Thread.sleep(5000);
// fila--;
// notify();
// if(fila==0) {
// lock = false;
// }
return text;
}
public static void main(String args) {
count = 0;
lock = false;
try {
AloMundoServidor obj = new AloMundoServidor();
AloMundo stub = (AloMundo) UnicastRemoteObject.exportObject(obj, 0);
Registry registry = LocateRegistry.getRegistry();
registry.bind("AloMundo", stub);
System.out.println("Servidor pronto!");
} catch (Exception e) {
System.err.println("Capturando excecao no Servidor: " + e.toString());
e.printStackTrace();
}
}
AluMundoCliente.java:
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class AloMundoCliente {
private AloMundoCliente() {}
public static void main(String args) {
String host = "54.244.xxx.xxx";
try {
Registry registry = LocateRegistry.getRegistry(host);
AloMundo stub = (AloMundo) registry.lookup("AloMundo");
String resposta = stub.digaAloMundo();
System.out.println("resposta: " + resposta);
} catch (Exception e) {
System.err.println("Capturando a exceção no Cliente: " + e.toString());
e.printStackTrace();
}
}
}
AloMundo.java
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface AloMundo extends Remote {
String digaAloMundo() throws Exception;
}
I execute telnet 54.244.xxx.xxx 1099 and its listing.
I tried java AloMundoServidor -Djava.rmi.server.hostname='54.244.xxx.xxx'
And no sucess!
Edit.:Solved
Launch cliente:
java -Djava.security.policy=server.policy AloMundoCliente
Modified ClienteCode in Registry with server IP:
Registry registry = LocateRegistry.getRegistry("xx.xx.xx.xx");
Create server.policy:
grant{
permission java.security.AllPermission;
};
Launch server:
java -Djava.security.policy=server.policy -Djava.rmi.server.hostname=XX.XX.XX.XX AloMundoServer
java windows amazon-web-services amazon-ec2 rmi
New contributor
Lucas Arkantos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I have two machines:
Server: AWS - EC2 - Ubuntu 18.04 Lts
Client: Windows 10
If I try run my code just in AWS machine it's work normally, but if i try same in other machine I have ConnectionRefused by time in Client machine
Code:
AloMundoServidor.java
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.io.*;
public class AloMundoServidor implements AloMundo {
private static int count, fila = 0;
private static boolean lock;
public AloMundoServidor() {}
public String digaAloMundo() throws Exception {
System.out.println("Chamada de aplicacao Cliente recebida! " + count);
/*fila++;
if(lock){
try {
wait();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
//Log.error("Thread interrupted", e);
}
}
lock = true;
*/
File file = new File("test.txt");
BufferedReader reader = new BufferedReader(new FileReader(file));
String text = "", line;
while ((line = reader.readLine()) != null) {
text = text + "n" + line;
}
count++;
Thread.sleep(5000);
// fila--;
// notify();
// if(fila==0) {
// lock = false;
// }
return text;
}
public static void main(String args) {
count = 0;
lock = false;
try {
AloMundoServidor obj = new AloMundoServidor();
AloMundo stub = (AloMundo) UnicastRemoteObject.exportObject(obj, 0);
Registry registry = LocateRegistry.getRegistry();
registry.bind("AloMundo", stub);
System.out.println("Servidor pronto!");
} catch (Exception e) {
System.err.println("Capturando excecao no Servidor: " + e.toString());
e.printStackTrace();
}
}
AluMundoCliente.java:
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class AloMundoCliente {
private AloMundoCliente() {}
public static void main(String args) {
String host = "54.244.xxx.xxx";
try {
Registry registry = LocateRegistry.getRegistry(host);
AloMundo stub = (AloMundo) registry.lookup("AloMundo");
String resposta = stub.digaAloMundo();
System.out.println("resposta: " + resposta);
} catch (Exception e) {
System.err.println("Capturando a exceção no Cliente: " + e.toString());
e.printStackTrace();
}
}
}
AloMundo.java
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface AloMundo extends Remote {
String digaAloMundo() throws Exception;
}
I execute telnet 54.244.xxx.xxx 1099 and its listing.
I tried java AloMundoServidor -Djava.rmi.server.hostname='54.244.xxx.xxx'
And no sucess!
Edit.:Solved
Launch cliente:
java -Djava.security.policy=server.policy AloMundoCliente
Modified ClienteCode in Registry with server IP:
Registry registry = LocateRegistry.getRegistry("xx.xx.xx.xx");
Create server.policy:
grant{
permission java.security.AllPermission;
};
Launch server:
java -Djava.security.policy=server.policy -Djava.rmi.server.hostname=XX.XX.XX.XX AloMundoServer
java windows amazon-web-services amazon-ec2 rmi
java windows amazon-web-services amazon-ec2 rmi
New contributor
Lucas Arkantos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Lucas Arkantos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited Nov 17 at 23:56
New contributor
Lucas Arkantos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked Nov 17 at 19:45
Lucas Arkantos
43
43
New contributor
Lucas Arkantos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Lucas Arkantos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Lucas Arkantos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Lucas Arkantos is a new contributor. Be nice, and check out our Code of Conduct.
Lucas Arkantos is a new contributor. Be nice, and check out our Code of Conduct.
Lucas Arkantos is a new contributor. Be nice, and check out our Code of Conduct.
Lucas Arkantos is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53354914%2fjava-rmi-aws-two-machine%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
X a2,jQ2v,yLcm06KohbwbVDFus03jx5HeDvgRFNdjyah,5T 5o77Ku Fp2joZkKvfQHP mOwCB jfsNCsjv Rrjnr0uMVTj29oMATPRUw y