Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
拒绝访问(“java.net.SocketPermission”错误发生在我在NetBeans中运行客户端项目时_Java_Rmi_Securitymanager - Fatal编程技术网

拒绝访问(“java.net.SocketPermission”错误发生在我在NetBeans中运行客户端项目时

拒绝访问(“java.net.SocketPermission”错误发生在我在NetBeans中运行客户端项目时,java,rmi,securitymanager,Java,Rmi,Securitymanager,java.security.AccessControlException:拒绝访问(“java.net.SocketPermission”“127.0.0.1:1099”“连接,解析”) 我的服务器端工作正常,服务器上没有错误..当我运行客户端代码时,我得到了拒绝访问的错误(“java.net.SocketPermission”“127.0.0.1:1099”“connect,resolve”) 请任何专家帮助我:( 这是我的客户代码 /** * * @author saqibhussain

java.security.AccessControlException:拒绝访问(“java.net.SocketPermission”“127.0.0.1:1099”“连接,解析”)

我的服务器端工作正常,服务器上没有错误..当我运行客户端代码时,我得到了拒绝访问的错误(“java.net.SocketPermission”“127.0.0.1:1099”“connect,resolve”)

请任何专家帮助我:(

这是我的客户代码

/**
 *
 * @author saqibhussain
 */
public class ChatClient extends UnicastRemoteObject implements ChatClientIF, Runnable {
public ChatClient() throws RemoteException {
}
private ChatServerIF chat;
private String name = null;

protected ChatClient(String name, ChatServerIF chat) throws RemoteException {        this.name = name;
    this.chat = chat;
    chat.RegisterChatClient(this);
}

public void retrieveMessage(String msg) throws RemoteException {
    System.out.println(msg);
}

public void run() {
    Scanner scaner = new Scanner(System.in);
    String message;
    while (true) {
        try {
            message = scaner.nextLine();
            chat.broadcastMessage(name + " : " + message);
        } catch (RemoteException ex) {
            Logger.getLogger(ChatClient.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

public static void main(String[] args) throws NotBoundException, MalformedURLException, RemoteException {
        System.setSecurityManager(new RMISecurityManager());

        try {
        String url = "rmi://localhost/RMIChatServer";
        ChatServerIF remoteObject = (ChatServerIF) Naming.lookup(url);
        System.out.println("Got remote object");
        new Thread(new ChatClient(args[0], remoteObject)).start();

        } catch (Exception e) {
        System.out.println(e);
        }
}
}

您已经定义了一个
SecurityManager
,但是您没有授予自己足够的权限来执行代码。您需要自己编写一个,并在启动时通过
-Djava.security.policy=…
将其指定给JVM


或者,只需删除安全管理器。除非您正在使用RMI代码库功能,否则不需要它。

向客户端应用程序添加安全策略。 您可以从以下位置下载示例策略:

之后,使用以下vm参数启动客户机

java -Djava.security.policy==client.policy
在生产环境中要小心,因为给定的策略授予
客户端执行的任何操作。

检查防火墙和端口取消阻塞。@Nambari否。这是一个
SecurityManager
问题。检查Javadoc。防火墙不会导致
java.security.AccessControlExceptions。