このコードは機能しません。まあ、それは動作しますが、クライアントは印刷しません。私は何か間違ったことをしていますか?W7とNetBeansを使用しています。rmiregistryに問題がないかどうかを確認する方法はありますか?これらのキャッチを削除すると、コンパイルできなくなります。問題は再バインドとルックアップに起因すると確信しています。
ServerNew.java:
interface C extends Remote
{
public String now() throws RemoteException ;
}
class Server extends UnicastRemoteObject implements C
{
public String now() throws RemoteException
{
return "99:99";
}
Server() throws RemoteException
{
}
}
public class ServerNew
{
public static void main(String[] args) throws Exception
{
Server server=new Server();
System.setSecurityManager(new java.rmi.RMISecurityManager());
LocateRegistry.createRegistry(1099);
Naming.rebind("rmi://localhost:1099/time", server);
}
}
ClientNew.java:
interface C extends Remote
{
public String now() throws RemoteException ;
}
public class ClientNew
{
public static void main(String[] args) throws Exception
{
C server=(C) Naming.lookup("rmi://localhost:1099/time");
String text=server.now();
System.out.println(text);
}
}
サーバーの出力(ServerNew.java:38
is Naming.rebind
):
Exception in thread "main" java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:1099" "connect,resolve")
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:366)
at java.security.AccessController.checkPermission(AccessController.java:555)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
at java.lang.SecurityManager.checkConnect(SecurityManager.java:1051)
at java.net.Socket.connect(Socket.java:574)
at java.net.Socket.connect(Socket.java:528)
at java.net.Socket.<init>(Socket.java:425)
at java.net.Socket.<init>(Socket.java:208)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:146)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)
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.newCall(UnicastRef.java:340)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at java.rmi.Naming.rebind(Naming.java:177)
at servernew.ServerNew.main(ServerNew.java:38)
Exception in thread "RMI TCP Connection(idle)" java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:61881" "accept,resolve")
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:366)
at java.security.AccessController.checkPermission(AccessController.java:555)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
at java.lang.SecurityManager.checkAccept(SecurityManager.java:1174)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.checkAcceptPermission(TCPTransport.java:654)
at sun.rmi.transport.tcp.TCPTransport.checkAcceptPermission(TCPTransport.java:293)
at sun.rmi.transport.Transport$1.run(Transport.java:176)
at sun.rmi.transport.Transport$1.run(Transport.java:174)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:553)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:808)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:667)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)