我试图使Oracle RMI-
IIOP示例
正常工作,但是在Netbeans中这样做却遇到了问题。
我的代码如下:
介面
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface HelloInterface extends Remote {
public void sayHello(String from) throws RemoteException;
}
接口实现
import java.rmi.RemoteException;
import javax.rmi.PortableRemoteObject;
public class HelloImpl extends PortableRemoteObject implements HelloInterface{
public HelloImpl() throws RemoteException
{
super();
}
public void sayHello(String from) throws RemoteException
{
System.out.println("Hello from " + from + "!!!");
System.out.flush();
}
}
服务器主
import javax.naming.Context;
import javax.naming.InitialContext;
public class HelloServer {
public static void main(String[] args) {
try {
System.setProperty("java.naming.factory.initial", "com.sun.jndi.cosnaming.CNCtxFactory");
System.setProperty("java.naming.provider.url", "iiop://localhost:1050");
// Step 1: Instantiate the Hello servant
HelloImpl helloRef = new HelloImpl();
// Step 2: Publish the reference in the Naming Service
// using JNDI API
Context initialNamingContext = new InitialContext();
initialNamingContext.rebind("HelloService", helloRef);
System.out.println("Hello Server: Ready...");
} catch (Exception e) {
System.out.println("Trouble: " + e);
e.printStackTrace();
}
}
}
和客户代码
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
public class HelloRMIIIOPClient {
public static void main(String[] args) {
Context ic;
Object objref;
HelloInterface hi;
try {
ic = new InitialContext();
System.setProperty("classpath", ".");
System.setProperty("java.naming.factory.initial", "com.sun.jndi.cosnaming.CNCtxFactory");
System.setProperty("java.naming.provider.url", "iiop://localhost:1050");
// STEP 1: Get the Object reference from the Name Service
// using JNDI call.
objref = ic.lookup("HelloService");
System.out.println("Client: Obtained a ref. to Hello server.");
// STEP 2: Narrow the object reference to the concrete type and
// invoke the method.
hi = (HelloInterface) PortableRemoteObject.narrow(
objref, HelloInterface.class);
hi.sayHello( " MARS " );
} catch( Exception e ) {
System.err.println( "Exception " + e + "Caught" );
e.printStackTrace( );
return;
}
}
}
我已经使用rmic生成存根和存根,并且服务器部分的代码工作正常,但是当我运行客户端代码时,我得到了:
Exception javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initialCaught
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at hellormiiiopnew.HelloRMIIIOPClient.main(HelloRMIIIOPClient.java:33)
BUILD SUCCESSFUL (total time: 0 seconds)
虽然这只是我的学习方法,但最终代码将用作模板,因此我可以通过Internet在分布式系统上传输简单对象。我一直在尝试使RMI在Internet上无法成功运行,因此这是我的最新尝试。任何帮助,尤其是示例,将不胜感激。
您需要先设置系统属性, 然后才能 创建InitialContext.
我对这家公司有着先入为主的厌恶滤镜,这源自自己作为消费者的直接评价、作为社会人的责任使然;此外,作为学生在与从基层到中层员工、从职能到业务人员的交流接触中,更加加深了这层滤镜。但需要说明的是,我十分幸运——最后遇到了很棒的老板和同事,让我出乎意料;奇葩的面试流程让我对面试有了更深刻的理解。 最后拿到offer对应的组真的挺棒的。做的事情算得上核心,也能发挥自己的特长,面试官/团队有技术,不过分卷;
问题内容: 首先,我已经阅读了很多关于我的问题的问题,但是它从来没有 给我解决方案。以下是一些有关 问题: 我在Web服务应用程序中使用Okhhtp3库。它工作 正常,但是当互联网连接速度慢或连接不可靠时,它就卡住了 ,永远不会超时,也永远不会调用超时异常或失败方法。 这是客户端代码: 20秒后如何获取超时异常或调用失败方法? Thanks 问题答案: 正如Trevor Halvorson指出的那
本文向大家介绍互联网和内联网之间的区别,包括了互联网和内联网之间的区别的使用技巧和注意事项,需要的朋友参考一下 Internet和Intranet都与网络有关,如果着眼于两个词,则仅具有一个字母的区别。但是,除了这些注意事项之外,两者之间还有许多明显的区别,下面将进行讨论。 以下是Internet和Intranet之间的重要区别 序号 键 互联网 内联网 1 定义 互联网是互连的计算机网络的全球系
我正在Java开发一个游戏,使用RMI进行所有网络通信。RMI允许我在服务器上调用方法,但对我来说还不够。我还希望服务器能够在连接的客户端之间传播消息。 我的客户机查找服务器(它的接口扩展为远程)并在其上注册。它允许服务器知道谁已连接。我的客户机还实现了一个扩展远程的接口。这是我的代码的一部分: 接口声明: 服务器端: 客户端: 此解决方案适用于本地,但当我尝试通过Internet使用它时则不起作
若要使用PS Vita与互联网连接,需先准备无线通信的环境。 若您的住家等地无法通过无线通信,可使用公众无线LAN服务(Hotspot)在公众场所与互联网连接。 公众无线LAN服务的使用方法与费用会因该服务的提供者而异。详细请询问该服务的提供者。 使用Wi-Fi连接 若要使用Wi-Fi与互联网连接,需准备以下内容。此外,接入点的设定通常会通过电脑进行。 与网络服务商签订合约 接入点或无线路由器 接
地址 # ipaddress_addresses.py import binascii import ipaddress ADDRESSES = [ '10.9.0.6', 'fdfd:87b5:b475:5e3e:b1bc:e121:a8eb:14aa', ] for ip in ADDRESSES: addr = ipaddress.ip_address(ip)