我目前使用使用JADE的基於Topic的通信。我可以使用jade.core.messaging.TopicManagementFEService
註冊JADE代理,從而連接到同一平臺上的主容器。無法通過JADE在android中接收ACLMessage
詳情如下:
- 主容器:一個簡單的LAMP/WAMP服務器託管的主要容器。
- 客戶端:連接到主容器的Android模擬器(測試目的)。
目前,
- 服務器啓動主容器
- Android模擬器連接到主容器成功(代理與主題管理服務創建沿啓用)
- Server是基於發送消息在一個特定的主題。
但我的Android客戶端無法收到此消息,雖然註冊的主題在兩端都是相同的!
你可以看到下面的代碼:
Server Side:
TopicManagementHelper topicHelper = (TopicManagementHelper) getHelper(TopicManagementHelper.SERVICE_NAME);
final AID sensorTopic = topicHelper.createTopic("JADE");
topicHelper.register(sensorTopic);
addBehaviour(new TickerBehaviour(this, TIMER_VALUE_IN_MILLISECONDS) {
private static final long serialVersionUID = -2567778187494378326L;
public void onTick() {
ACLMessage msg = new ACLMessage(ACLMessage.INFORM);
msg.addReceiver(eventTopic);
msg.setContent(eventValue);
myAgent.send(msg);
}
});
Android Side:
// Registering on Android Side as well
TopicManagementHelper topicHelper = (TopicManagementHelper) getHelper(TopicManagementHelper.SERVICE_NAME);
topic = topicHelper.createTopic("JADE"); // See, same topic!
topicHelper.register(topic);
behaviour = new myBehaviour(this, TIMER_VALUE_IN_MILLISECONDS, topic);
addBehaviour(behaviour);
private class myBehaviour extends TickerBehaviour {
private static final long serialVersionUID = 4782913834042415090L;
AID topic;
Agent agent;
MessageTemplate tpl;
public myBehaviour(Agent a, long period, AID topic) {
super(a, period);
this.agent = a;
this.topic = topic;
}
public void onTick() {
tpl = MessageTemplate.MatchTopic(topic);
ACLMessage msg = receive(tpl);
if (msg != null) {
logger.log(Level.INFO, "Agent "+ agent.getLocalName() +
": Message about topic "+ topic.getLocalName() +" received. \n" +
"Content is " + msg.getContent());
data = msg.getContent();
} else {
logger.log(Level.INFO, "In here..."); // Always executes only this code!
block();
}
}
}
我要去哪裏錯了嗎?它總是執行Android側的else
部分,這很明顯地表示收到的消息是NULL!
請幫我回答一個問題。我們可以在Android設備上啓動一個玉器服務器(代理平臺)嗎?如果可以的話,該怎麼做? –