如何使用RMI创建计算器? [英] How to create calculator using RMI?

查看:224
本文介绍了如何使用RMI创建计算器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习Java,现在我的专长是使用RMI扩展的计算器.

现在,我已经准备好编写所有计算器代码(包括运算符和所有计算-所有数学代码...),但是我的问题是如何使用RMI来运行它.

我在Google Serch上看到我需要clinet和服务器代码,但我不太了解..

我希望得到一个简单的示例,说明我的代码应如何显示,以便我拿起计算器并在其上进行构建.

有人可以帮忙吗?

这是我的服务器代码:

I am learning java and now my excersize is bulding calculator using RMI.

Now, i have allready write all calculator code(with the opertors and all the calculation - all the math code...) but my problem is how to use RMI to run it.

I saw on google serch that i need clinet and server code but i dont really understand it..

I hope to get simple example of how my code should be looking like so i will take my calculator and build on it.

Can someone please help ?

here is my server code :

import java.rmi.Naming;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

public class ServerProgram 
{
    public ServerProgram() 
    {
        try 
        {
            Registry registry = LocateRegistry.getRegistry();
            System.out.println("1");

            CalculatorImpl c = new CalculatorImpl();

            String name = "rmi://host:port/name";

            System.out.println("2");
            Naming.rebind(name, c);

            System.out.println("Service is bound......");
        } 
        catch (Exception e)
        {
        }
    }

    public static void main(String[] args)
    {
        new ServerProgram();
    }
}


但是当我运行它时,我在调试中看到它卡在


but when i run it i see on debug that it is stuck on

Naming.rebind(name, c)

上,我不知道为什么或如何修复它.

等待你们的帮助..

, and i dont know why or how to fix it.

wait fo you guys help..

推荐答案

RMI的解释很简单,但有代码示例和良好的参考,这里:
http://en.wikipedia.org/wiki/Java_remote_method_invocation [
—SA
RMI is explained very well, in a nutshell but with code samples and good references, here:
http://en.wikipedia.org/wiki/Java_remote_method_invocation[^].

However, I would be very curious where such though could come from. Why won''t you try to implement a calculator using Large Hadron Collider or something equally impressive? :-)

—SA


我知道我的夸张说法是我必须使用RMI进行练习和学习..

您知道我的服务器代码有什么问题吗?
i know it just that my excessive said i must use RMI for practice and learn..

do you know whats wrong at my server code ?


这篇关于如何使用RMI创建计算器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆