[英]Client, server and rmi don't work
This code doesn't work.此代码不起作用。 Well, it works, but the client doesn't print.
好吧,它有效,但客户端不打印。 Am i doing something wrong?
难道我做错了什么? I'm using W7 and NetBeans.
我正在使用 W7 和 NetBeans。 Is there a way to see if the rmiregistry is ok?
有没有办法查看 rmiregistry 是否正常? If i remove these catch, i can't compile it.
如果我删除这些捕获,我将无法编译它。 I'm pretty sure that problems come from rebind and lookup.
我很确定问题来自重新绑定和查找。
ServerNew.java: 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: 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);
}
}
Output for Server ( ServerNew.java:38
is Naming.rebind
):服务器的输出(
ServerNew.java:38
是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)
With that exception handling it is impossible for anybody to answer your question.通过这种异常处理,任何人都无法回答您的问题。 I suggest you fix it and provide the exception that is being thrown.
我建议您修复它并提供正在抛出的异常。 What you have posted so far is completely pointless and should never have been written.
到目前为止,您发布的内容完全没有意义,不应该写。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.