📄 remoteclient.java
字号:
package abrobot.abmobilerobot.clinet;
/**
* <p>Title: GOPDR</p>
* <p>Description: General Open Platform for Distributed Robot</p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: SJTU</p>
* @author Hou Xueqiao
* @version 1.01
*/
import abrobot.*;
import java.rmi.RMISecurityManager;
import net.jini.discovery.LookupDiscovery;
import net.jini.core.lookup.ServiceTemplate;
import net.jini.discovery.LookupDiscoveryManager;
import net.jini.lookup.ServiceDiscoveryManager;
import net.jini.core.lookup.ServiceItem;
import net.jini.lease.LeaseRenewalManager;
import net.jini.core.discovery.LookupLocator;
public class RemoteClient {
private static final long WAITFOR = 100000L;
AbRobotInterface Robot;
public void getRemoteRobot(String GatewayHostName){
ServiceDiscoveryManager clientMgr = null;
//singlecast locate the jiniReggie on which robot register and tunnel run
System.setSecurityManager(new RMISecurityManager());
try {
LookupLocator[] locators=new LookupLocator[]{new LookupLocator(GatewayHostName,4160)};
LookupDiscoveryManager mgr =
new LookupDiscoveryManager(LookupDiscovery.ALL_GROUPS,
locators /* singlecast locators */,
null /* DiscoveryListener */);
System.out.println(mgr.getRegistrars().length);
clientMgr = new ServiceDiscoveryManager(mgr,
new LeaseRenewalManager());
} catch(Exception e) {
e.printStackTrace();
System.exit(1);
}
Class [] classes = new Class[] {AbRobotInterface.class};
ServiceTemplate template = new ServiceTemplate(null, classes,
null);
ServiceItem item = null;
if (clientMgr==null) System.out.println("NO Reggie");
// Try to find the service, blocking till timeout if necessary
try {
item = clientMgr.lookup(template,
null, /* no filter */
WAITFOR /* timeout */);
} catch(Exception e) {
e.printStackTrace();
System.exit(1);
}
if (item == null) {
// couldn't find a service in time
System.out.println("no service");
System.exit(1);
}
try{
Robot= (AbRobotInterface)item.service;
System.out.println("RobotTag"+Robot.Properties().getProperty("Tag"));
}catch(Exception e){
e.printStackTrace();
}
// Get the service
System.exit(0);
}
public RemoteClient() {
}
public static void main(String[] args) {
RemoteClient remoteClient1 = new RemoteClient();
remoteClient1.getRemoteRobot("202.120.8.136");
try {
Thread.currentThread().sleep(2*WAITFOR);
} catch(java.lang.InterruptedException e) {
// do nothing
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -