简体   繁体   English

使用的Rmi服务器端口alrady

[英]Rmi server port alrady used

I want to run simple rmi server code below. 我想在下面运行简单的rmi服务器代码。 Firstly, I write command "rmiregistry 9260" and so I started the rmi register. 首先,我编写命令“ rmiregistry 9260”,然后启动rmi寄存器。 Then I run following code but I get errors. 然后我运行以下代码,但出现错误。 What can cause these errors? 什么会导致这些错误? Note that I tried different port numbers. 请注意,我尝试了其他端口号。

public class Server {

    public static void main(String args[]) {

        try {
            PaymentImpl robj = new PaymentImpl();
            Payment stub = (Payment) UnicastRemoteObject.exportObject(robj, 9260);

            Registry registry = LocateRegistry.getRegistry();
            registry.bind("Mortgage", stub);
            System.out.println("Mortgage Server is ready to listen... ");

        } catch (Exception e) {
            System.err.println("Server exception thrown: " + e.toString());
            e.printStackTrace();
        }
    }
}


Server exception thrown: java.rmi.server.ExportException: Port already in use
260; nested exception is:
        java.net.BindException: Address already in use
java.rmi.server.ExportException: Port already in use: 9260; nested exception

        java.net.BindException: Address already in use
        at sun.rmi.transport.tcp.TCPTransport.listen(Unknown Source)
        at sun.rmi.transport.tcp.TCPTransport.exportObject(Unknown Source)
        at sun.rmi.transport.tcp.TCPEndpoint.exportObject(Unknown Source)
        at sun.rmi.transport.LiveRef.exportObject(Unknown Source)
        at sun.rmi.server.UnicastServerRef.exportObject(Unknown Source)
        at java.rmi.server.UnicastRemoteObject.exportObject(Unknown Source)
        at java.rmi.server.UnicastRemoteObject.exportObject(Unknown Source)
        at Server.main(Server.java:14)
Caused by: java.net.BindException: Address already in use
        at java.net.PlainSocketImpl.socketBind(Native Method)
        at java.net.AbstractPlainSocketImpl.bind(Unknown Source)
        at java.net.ServerSocket.bind(Unknown Source)
        at java.net.ServerSocket.<init>(Unknown Source)
        at java.net.ServerSocket.<init>(Unknown Source)
        at sun.rmi.transport.proxy.RMIDirectSocketFactory.createServerSocket(
nown Source)
        at sun.rmi.transport.proxy.RMIMasterSocketFactory.createServerSocket(
nown Source)
        at sun.rmi.transport.tcp.TCPEndpoint.newServerSocket(Unknown Source)
        ... 8 more

If you're using 9260 for a separate Registry process you can't use it again in this process. 如果您将9260用于单独的注册表过程,则不能在此过程中再次使用它。 You can use 9260 for both by starting the Registry in this process, with LocateRegistry.createRegistry(). 通过在此过程中启动注册表,可以使用LocateRegistry.createRegistry()将9260用于这两种方法。 Store the return value into a static variable to prevent GC. 将返回值存储到静态变量中以防止出现GC。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM