2014-01-07 44 views
1

java.security.AccessControlException:訪問被拒絕(「java.net.SocketPermission」「127.0.0.1:1099」「connect,resolve 「)訪問被拒絕(「java.net.SocketPermission」錯誤當我在NetBeans中運行我的CLient項目時

我的服務器端是完美的工作,沒有服務器錯誤..而當我運行我的客戶端代碼訪問被拒絕(」java.net.SocketPermission「」127.0.0.1:1099「」連接,解決「)這個錯誤發生,請,,任何高手幫我:(

這是我的客戶端代碼

/** 
* 
* @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 reteriveMessage(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); 
     } 
} 
} 
+0

檢查防火牆和端口解除阻塞。 – kosa

+1

@Nambari號這是一個'SecurityManager'問題。檢查Javadoc。防火牆不能導致java.security.AccessControlExceptions.' – EJP

回答

0

你已經定義了一個SecurityManager,但是你還沒有給自己足夠的權限來執行你的代碼。您需要自己寫一個policy file,並在通過-Djava.security.policy=...啓動時將其指定給JVM。

或者,刪除安全管理器。除非您使用RMI代碼庫功能,否則不需要它。

相關問題