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);
}
}
}
檢查防火牆和端口解除阻塞。 – kosa
@Nambari號這是一個'SecurityManager'問題。檢查Javadoc。防火牆不能導致java.security.AccessControlExceptions.' – EJP