1 year ago

#305816

test-img

Michael Jones

Java RMI permission denied to LAN address, works for 127.0.0.1

I am implementing a Client application and a Server application on my Windows computer using two terminals that communicate with each other.

However I cannot get the Client to run. The Server and Java RMI registry run successfully. I have 3 files: Client.java, Server.java and Hello.java

import java.rmi.registry.LocateRegistry; //Client.java
import java.rmi.registry.Registry;

public class Client { 

    private Client() {}

    public static void main(String[] args) {

        String host = (args.length < 1) ? null : args[0];
        try {
        
            Registry registry = LocateRegistry.getRegistry("127.0.0.1", 1099);
            Hello stub = (Hello) registry.lookup("Hello");
            String response = stub.sayHello();
            System.out.println("response: " + response);
        } catch (Exception e) {
            System.err.println("Client exception: " + e.toString());
            e.printStackTrace();
        }
    }
}  
import java.rmi.registry.Registry; //Server.java
import java.rmi.registry.LocateRegistry;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
        
public class Server implements Hello {
        
    public Server() {}

    public String sayHello() {
        return "Hello, world!";
    }
        
    public static void main(String args[]) {
        
        try {
            Server obj = new Server();
            Hello stub = (Hello) UnicastRemoteObject.exportObject(obj, 0);

            // Bind the remote object's stub in the registry
            Registry registry = LocateRegistry.getRegistry("127.0.0.1", 1099);
            registry.bind("Hello", stub);

            System.err.println("Server ready");
        } catch (Exception e) {
            System.err.println("Server exception: " + e.toString());
            e.printStackTrace();
        }
    }
}
import java.rmi.Remote; //Hello.java
import java.rmi.RemoteException;

public interface Hello extends Remote {
    String sayHello() throws RemoteException;
}

All three Java files are located in C:\Program Files\Java\jdk1.8.0_321\bin. After compiling them to the same directory, I run the following commands in the command prompt as administrator.

  1. start rmiregistry -J-Djava.class.path=./

Java RMI registry starts successfully in a new command prompt window (no output).

  1. start java Server

Server starts sucessfully in a new command prompt which outputs "Server ready".

  1. java Client

This command is unsuccessful and outputs the following error:

        java.net.SocketException: Permission denied: connect
java.rmi.ConnectIOException: Exception creating connection to: 192.168.1.13; nested exception is:
        java.net.SocketException: Permission denied: connect
        at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:635)
        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:131)
        at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:235)
        at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:180)
        at com.sun.proxy.$Proxy0.sayHello(Unknown Source)
        at Client.main(Client.java:15)
Caused by: java.net.SocketException: Permission denied: connect
        at java.net.DualStackPlainSocketImpl.connect0(Native Method)
        at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:75)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:476)
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:218)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:200)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:162)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:394)
        at java.net.Socket.connect(Socket.java:606)
        at java.net.Socket.connect(Socket.java:555)
        at java.net.Socket.<init>(Socket.java:451)
        at java.net.Socket.<init>(Socket.java:228)
        at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
        at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:148)
        at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:617)
        ... 7 more

C:\Program Files\Java\jdk1.8.0_321\bin>_

I am unsure how to get the Client running successfully. I disabled windows firewall and am not using a VPN.

java

rmi

0 Answers

Your Answer

Accepted video resources