小编Cha*_*lam的帖子

java.rmi.server.ExportException:端口已在使用中:1099;

我正在编写一个 Java RMI 程序来计算数字的阶乘。

这是界面:

import java.rmi.Remote;
import java.rmi.RemoteException;

public interface FactorialRMI extends Remote{

    public void setNumber(int val) throws RemoteException;
    public int calculateFactorial() throws RemoteException;
}
Run Code Online (Sandbox Code Playgroud)

那么这是实现该接口的类:

import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

public class FactorialRMIImpl extends UnicastRemoteObject implements FactorialRMI{
    private int number;
    public FactorialRMIImpl(String name) throws RemoteException {
        super();
        try {
            Naming.rebind("myFactorial",this);
        }catch(Exception e) {
            System.out.println("Exception: "+e.getMessage());
        }
    }

    @Override
    public void setNumber(int val) throws RemoteException {
        this.number=val;
    }

    @Override
    public int calculateFactorial() throws RemoteException {
        int p=1;
        for(int …
Run Code Online (Sandbox Code Playgroud)

java rmi server

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

java ×1

rmi ×1

server ×1