AllJoyn简单应用程序代码示例——echo

哥特帝景 2014-03-31 05:51:38
echo 总线接口定义:
import org.alljoyn.bus.BusException;
import org.alljoyn.bus.annotation.BusInterface;
import org.alljoyn.bus.annotation.BusMethod;
/*
* This interface implements a simple echo method that returns the same string
* that is receives.
*/
@BusInterface public interface EchoInterface {
/*
* Echo a string.
*
* inStr is the string to be echoed by the service, returns the echoed string.
*/
@BusMethod(signature="s", replySignature="s") public
String Echo(String inStr) throwsBusException;
}

Service端:
public class Service implementsSimpleInterface, BusObject {
public static void main(String[] args) {
/* Create a bus connection and connect to the bus */
BusAttachment bus = new BusAttachment(Service.class.getName());
bus.connect();
/* Register the service */
Service service = newService();
bus.registerBusObject(service, "/myobject");
/* Request a well-known name */
try{
bus.RequestName("org.alljoyn.echo", REQUEST_NAME_NO_FLAGS);
} catch(BusException ex) {
return;
}
/* Echo until told to stop */
while(!stop) { Thread.sleep(10000); }
}
/* Implementation of the echo method */
publicString Echo(String inStr) {
returninStr;
}
}

Client端:
public class Client {
public static void main(String[] args) {
/* Create a bus connection and connect to the bus */
BusAttachment bus = new BusAttachment(Client.class.getName());
bus.connect();
/* Get a remote object */
Class[] ifaces = { EchoInterface.class };
ProxyBusObject proxyObj = bus.getProxyBusObject("org.alljoyn.echo", "/myobject", ifaces);
SimpleInterface proxy = proxyObj.getInterface(EchoInterface.class);
/* Call the ping method on the remote object */
try{
String ret = proxy.Echo("Hello World");
System.out.println(“Echo returned: " + ret);
} catch(BusException ex) {
return;
}
}
}

官方网站:
https://www.alljoyn.org
https://developer.qualcomm.com/develop/mobile-technologies/peer-peer-alljoyn
...全文
1898 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

2,852

社区成员

发帖
与我相关
我的任务
社区描述
本论坛以AI、WoS 、XR、IoT、Auto、生成式AI等核心板块组成,为开发者提供便捷及高效的学习和交流平台。 高通开发者专区主页:https://qualcomm.csdn.net/
人工智能物联网机器学习 技术论坛(原bbs) 北京·东城区
社区管理员
  • csdnsqst0050
  • chipseeker
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧