启动程序以在指定端口上运行后,程序会在客户端能够连接之前终止。
user-select: none;
color: #00000000; /* hex RRGGBBAA, AA=00 means 0% opacity, so the text is invisible */
这是位于已被覆盖的StudentService类中的方法。
try {
StudentService obj = new StudentService();
Registry r = LocateRegistry.createRegistry(4200);
r.bind("localhost", obj);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (AlreadyBoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
答案 0 :(得分:0)
从文档中
UnicastRemoteObject.exportObject导出提供的远程对象以接收匿名TCP端口上的传入远程方法调用,并返回远程对象的存根以传递给客户端
因此,没有收听传入连接,程序结束就不足为奇了。这应该有用。
try {
StudentService obj = new StudentService();
UnicastRemoteObject.exportObject(obj, 0);
Registry r = LocateRegistry.createRegistry(4200);
r.bind("localhost", obj);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (AlreadyBoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}