我在写了一个很简单的测试程序,发现没有办法运行。请大家指点。
代码如下:
import java.rmi.Remote;public interface SerInterface extends Remote{}
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
public class ServerImpl extends UnicastRemoteObject implements SerInterface {
private static final long serialVersionUID = 1L;
public ServerImpl()throws RemoteException{
System.out.println("server is strating ...");
}
public void f(){
System.out.println("a client call");
}
}
import java.rmi.Naming;
import java.rmi.registry.LocateRegistry;
public class Server {
public static void main(String[] args) {
System.out.println("a client is strating...");
System.out.println("hello");
try {
LocateRegistry.createRegistry(1099);
ServerImpl si = new ServerImpl();
System.out.println("binging server...");
Naming.rebind("server",si);
System.out.println("waiting for invocations from clients...");
} catch (Exception e) {
e.printStackTrace();
} }}
import java.rmi.Naming;
public class Client{
public static void main(String[] args){
try {
ServerImpl s = (ServerImpl)Naming.lookup("server");
s.f();
} catch (Exception e) {
e.printStackTrace();
}
}
}java.lang.ClassCastException: $Proxy0 cannot be cast to ServerImpl服务器可以跑起来,客户端是不行的。
请问是什么原因呀?
代码如下:
import java.rmi.Remote;public interface SerInterface extends Remote{}
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
public class ServerImpl extends UnicastRemoteObject implements SerInterface {
private static final long serialVersionUID = 1L;
public ServerImpl()throws RemoteException{
System.out.println("server is strating ...");
}
public void f(){
System.out.println("a client call");
}
}
import java.rmi.Naming;
import java.rmi.registry.LocateRegistry;
public class Server {
public static void main(String[] args) {
System.out.println("a client is strating...");
System.out.println("hello");
try {
LocateRegistry.createRegistry(1099);
ServerImpl si = new ServerImpl();
System.out.println("binging server...");
Naming.rebind("server",si);
System.out.println("waiting for invocations from clients...");
} catch (Exception e) {
e.printStackTrace();
} }}
import java.rmi.Naming;
public class Client{
public static void main(String[] args){
try {
ServerImpl s = (ServerImpl)Naming.lookup("server");
s.f();
} catch (Exception e) {
e.printStackTrace();
}
}
}java.lang.ClassCastException: $Proxy0 cannot be cast to ServerImpl服务器可以跑起来,客户端是不行的。
请问是什么原因呀?
解决方案 »
- can bind a LONG value only for insert into a LONG column
- JPA到底是神马
- hibernate配置文件的一些问题
- Access denied for user 'root'@'localhost' (using password: NO)
- 错误 Application was not properly initialized at startup, could not find Factory:
- 请求帮助,JAVA连接数据库问题
- 关于NIO的问题,跪求
- 设计实现一个能点对点聊天的Java程序,大家给点思路!?
- JVM 内存溢出
- 北京用友工程公司怎么样,听说给惠普作项目,知道的介绍一下,谢谢
- struts2.1.6 类型转换
- 诚心请教高手 :使用JDBC更新ORACLE数据
import java.rmi.Remote;public interface SerInterface extends Remote{ public void f() throws RomoteException;} 我觉得现在应该可以了,不过我没法试
LZ你没结过帖??????????
LZ你没结过帖??????????
rmic cn.wzh.ServerImpl
将会生成stub存根对象,也就是你的远程代理对象你在client端main方法应该使用接口调用
SerInterface s = (SerInterface)Naming.lookup("server");启动Server时,注意启动RMI服务器
开始 -> 运行 -> start rmiregistry