I'm trying to use racer (Description Logic reasoner), but i get the following error
com.racersystems.jracer.RacerClientException: Connection refused: connect
at com.racersystems.jracer.RacerClient.openConnection(RacerClient.java:76)
at test.Test.main(Test.java:12)
the code i'm executing is the following :
package test;
import com.racersystems.jracer.*;
public class Test {
public static void main(String[] argv) {
String ip = "127.0.0.1";
int port = 8088;
String filename="\"/jracer-2-0.zip_expanded/jracer-2-0/demo/people+pets.owl\"";
RacerClient racer = new RacerClient(ip,port);
try {
racer.openConnection();
System.out.println(racer.sendRaw("(owl-read-file " + filename + ")"));
System.out.println(racer.sendRaw("(all-atomic-concepts)"));
racer.closeConnection();
}
catch (Exception e) {
e.printStackTrace();
}
}}
I don't know who to solve it ?
Any suggestions ?
You are apparently trying to connect to a service that is running on the same machine as you are running the program ... using the 127.0.0.1 loopback interface.
The fact that it is giving you a "connection refused" response means that the service is not currently running on "this machine" or the port that you have specified.
The solution will be to ensure that the service is running and listening on the specified IP and port; e.g. check the IP address and port, and start or restart the service.
Related
So far I have achieved making server/client relations on the same computer by parallelly running different java classes. As I don't want to overcomplicate this question, I will post my simplified code which works perfectly fine.
Server:
public class Server {
public static final int PORT = 9090;
public static void main (String[] args) {
try {
ServerSocket serverSocket = new ServerSocket (PORT);
Socket client = serverSocket.accept ();
System.out.println ("Client connected!");
} catch (IOException ioException) {
ioException.printStackTrace ();
}
}
}
Client:
public class Client {
public static final int PORT = 9090;
public static final String IP_ADDRESS = "127.0.0.1";
public static void main (String[] args) {
try {
Socket socket = new Socket (IP_ADDRESS,PORT);
} catch (IOException ioException) {
ioException.printStackTrace ();
}
}
}
After I run them, I get the expected output - console in class Server prints "Client connected!".
Like any other curious programmer, I decided to try out the same program on my two laptops. One laptop has client code, while second has server code. Of course, I had to change "127.0.0.1" or "localhost" to ip address my server laptop has by typing on google "what is my IP address". I just copied that new IP address into IP_ADDRESS variable and hoped it would work the same. Unfortunately, it didn't happen. My client laptop looks as if it never connected to server laptop, because server laptop never printed message "Client connected!". What am I missing? It looks so easy, yet it doesn't work. Could someone help me solve this?
P.S. I don't want to share my IP address due to privacy reasons, but it was the first number that pops when any of you google: what is my IP address?
If you are on a local network, you don't have to take your public IP. You need to find your local IP (if you are on linux, a simple "ip a" and you'll have your IP address, if you are on windows )
If you are not on a local network, you could open your router' settings to open the 9090 port but I STRONGLY discourage you to do something like that for security reason.
I'm trying to get remote objects from a server hosted on different network. I'm able to connect on same machine and on same network, but when I try to get it from different network I get:
Connection refused to host: 192.168.1.131; nested exception is: java.net.ConnectException: Connection timed out: connect
It seems that lookup function is searching at wrong network. I tried to use System.setProperty but it doesn't work. Here the code:
Server
public class Main {
public static void main(String[] args) {
try{
System.out.println("Init server...\n");
TestInterface test = new TestImplement();
System.setProperty("java.rmi.server.hostname", "95.247.x.x");
System.out.println("Reg RMI...\n");
Registry rmiRegistry = LocateRegistry.createRegistry(5555);
rmiRegistry.rebind("Test" , test);
System.out.println("Reg completed!\n");
}catch(Exception e){
e.printStackTrace();
}
}
}
Client
...
registryRMI = LocateRegistry.getRegistry("95.247.x.x",5555);
TestInterface testClient = (TestInterface)registryRMI.lookup("Test");
...
Do I need to set java.rmi.server.hostname in client jar as well?
TestInterface test = new TestImplement();
System.setProperty("java.rmi.server.hostname", "95.247.x.x");
You need to set java.rmi.server.hostname before exporting any remote objects. Doing it afterwards is too late.
System.setProperty("java.rmi.server.hostname", "95.247.x.x");
TestInterface test = new TestImplement();
I am sure that I am using the correct connection information:
import com.bmc.arsys.api.ARException;
import com.bmc.arsys.api.ARServerUser;
/**
*
* A class to automate deletion of BMC Remedy incidents after deploying or decommissioning servers
*
*/
#SuppressWarnings("unused")
public class BMCIncidentDelete {
public static void main(String[] args) {
/*
* Authentication information
*/
String host = "";
String server = "";
String user = "";
String pass = "";
ARServerUser ctx = new ARServerUser();
ctx.setServer(host);
// ctx.setServer(server);
ctx.setUser(user);
ctx.setPassword(pass);
ctx.setPort(8080);
/*
* Verify user or print stack trace if not possible
*/
try {
ctx.verifyUser();
System.out.println("Connection verified!");
} catch (ARException e) {
System.out.println(e.getMessage().toString());
}
}
}
Unfortunately, I get the following error:
ERROR (90): Cannot establish a network connection to the AR System server; Connection refused: connect
Anyone with experience with the AR System API see this issue before? https://communities.bmc.com/docs/DOC-17514
This error (Connection refused) indicates that the Remedy server is not reachable from your server on the host and port provided. You can validate by using telnet, substituting the hostname for $host:
$ telnet $host 8080
A successful connection should say "Connected to host.", but based on your question you will likely see "Connection refused". Double check the hostname and port number of the Remedy server, and if necessary check that there are no firewalls, etc. between you and the server.
I am not so experienced in Java RMI. I am trying to implement simple RMI communication, but faced with the problem.
Here my RMI client
public class MainClientApplication {
public static final String FILE_NAME_RMI_POLICY = "rmi.policy";
public static final String RMI_DOMAIN = "mydomain.net";
public static final String RMI_ENDPOINT = "/MD5Decrypter";
public static final String PROTOCOL = "rmi://";
public static void main(String[] args) {
System.out.println(System.getProperty("user.dir") + File.separator + FILE_NAME_RMI_POLICY);
System.setProperty("java.security.policy", System.getProperty("user.dir") + File.separator + FILE_NAME_RMI_POLICY);
String remoteHost = String.format("%s%s%s", PROTOCOL, RMI_DOMAIN, RMI_ENDPOINT);
System.setSecurityManager(new SecurityManager());
try {
ComputeEngine computeEngine = (ComputeEngine) Naming.lookup(remoteHost);
SwingUtilities.invokeLater(() -> new MainWindow("MD5 Decryption", computeEngine));
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
Communication inerface
public interface ComputeEngine extends Remote {
Object executeTask(Task t) throws RemoteException;
}
My server
public class MainServer {
public static final int PORT = 1099;
public static final String RMI_ENDPOINT = "MD5Decrypter";
public static final String FILE_NAME_RMI_POLICY = "rmi.policy";
public static final String RMI_DOMAIN = "mydomain.net";
public static final String PROTOCOL = "rmi://";
public MainServer() {
try {
System.setProperty("java.security.policy", System.getProperty("user.dir") + File.separator + FILE_NAME_RMI_POLICY);
//System.setProperty("java.rmi.server.hostname", RMI_IP);
System.setProperty("java.rmi.server.hostname", RMI_DOMAIN);
System.setSecurityManager(new SecurityManager());
ComputeEngine computeEngine = new ComputeEngineExecutor();
// Naming.rebind(String.format("%s%s:%d/%s", PROTOCOL, RMI_DOMAIN, PORT, RMI_ENDPOINT), computeEngine);
Naming.rebind(RMI_ENDPOINT, computeEngine);
System.out.println("Successfully started RMI Server");
} catch (RemoteException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
MainServer mainServer = new MainServer();
}
}
And rmi.policy
grant {
permission java.net.SocketPermission "*:1024-65535", "connect, accept";
permission java.io.FilePermission "-", "read";
permission java.net.SocketPermission "*:80", "connect";
};
So I have started rmiregistry on my server rmiregistry 1099. And everything works well until calling remote object method.
Here are my steps
Lets consider that my domain is mydomain.net , I host it on my server at home with static IP.
Run rmiregistry on the server
Run server application on the server
Run client application on any PC
Click button to invoke remote method
So it seems that everything connects and binds successfully, because if force enter invalid domain, endpoint or refused if rmiregistry is not started - java.rmi.ConnectException is thrown.
But when I try to invoke any method on remote object, BTW which has been already retrieved successfully it throws a java.rmi.ConnectException
java.rmi.ConnectException: Connection refused to host: 127.0.1.1; nested exception is:
java.net.ConnectException: Connection refused
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:130)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:227)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:179)
at com.sun.proxy.$Proxy0.executeTask(Unknown Source)
at ui.MainWindow.lambda$initGui$0(MainWindow.java:49)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
As I can understand the problem is that it (server) forces me to connect to my localhost instead of remote.
P.S on localhost everything works perfectly (both client and server on the one PC)
Please help to solve this problem.
EDIT
I have forgotten to tell that I have tried to set property of java.rmi.server.hostname, in this case it takes a lot of time to start the server and ends with exception.
Leaving the 127.0.0.1 issue aside, which is solved by java.rmi.server.hostname, your problem now is connect timeouts. This will be caused by your firewall. You need to export your remote object on a specific port, and you need to open that TCP port in your firewall.
I'm try to set up a simple RMI implementation, but I'm having some trouble.
The server starts up fine, but the client can never seem to find the remote object (Naming.lookup fails every time). From reading around people have mentioned storing the remote object (Bank) in a static variable, but that hasn't worked either.
UPDATE: If I remove all references to the port number, the whole thing seems to work fine. Does anyone know why that is?
Server:
public class Bank extends UnicastRemoteObject implements BankInterface {
public static void main(String args[]) throws Exception {
try{
System.setSecurityManager(new SecurityManager());
System.out.println("Security Manager set.");
Bank myBank = new Bank(Integer.parseInt(args[0]));
System.out.println("Bank instance created");
Naming.rebind("Bank", myBank);
System.out.println("Name rebind completed.");
System.out.println("Server ready for requests!");
}catch(Exception e){
System.out.println("Error in main - " + e.toString());
}
}
}
Client
public class ATM {
public static void main (String args[]) throws Exception {
String URL = "//" + args[0] + ":" + args[1] + "/Bank";
System.out.println("Connecting to: " + URL);
BankInterface bank = (BankInterface)Naming.lookup(URL);
System.out.println("Connected!");
}
}
Stacktrace
Exception in thread "main" java.rmi.NoSuchObjectException: no such object in tab
le
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Stream
RemoteCall.java:276)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:
253)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:379)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Naming.java:101)
at ATM.main(ATM.java:8)
Commands I'm running from cmd.exe are:
rmiregistry
java Bank 7777
java ATM localhost 7777 testMethod
You're running the Registry on its default port, and binding to that Registry, by not using a port number in the bind string, but you're looking up a non-existent Registry on port 7777. The bind string and the lookup string should be the same.
NB lookup isn't the same as connecting. There is no connection to your remote object until you call one of its remote methods.