我們在這裏遇到了一個項目上的奇怪問題。當我們將NetConnection與NetGroup結合使用以在Windows XP上啓動兩個本地AIR應用程序之間的通信時,它們始終都會成功連接到NetGroup,並將相互檢測爲鄰居。但是,在Windows 7上,兩個應用程序都成功連接到NetConnection,並且NetGroup都不會將相互檢測爲鄰居。RTMFP直接點對點連接在Windows XP上運行,但在Windows 7上運行
要重現這個問題,這裏有兩個AIR應用程序:
RTMFP1:
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
applicationComplete="init()">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
private var nc:NetConnection;
private var group:NetGroup;
[Bindable]
private var connected:Boolean = false;
private function init():void
{
connect();
}
private function connect():void
{
nc = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
nc.connect("rtmfp:");
}
private function netStatus(event:NetStatusEvent):void
{
writeText(event.info.code);
switch (event.info.code)
{
case "NetConnection.Connect.Success":
setupGroup();
break;
case "NetGroup.Connect.Success":
connected = true;
break;
case "NetGroup.Posting.Notify":
receiveMessage(event.info.message)
break;
}
}
private function setupGroup():void
{
var groupspec:GroupSpecifier = new GroupSpecifier("myGroup/groupOne");
groupspec.postingEnabled = true;
groupspec.ipMulticastMemberUpdatesEnabled = true;
groupspec.addIPMulticastAddress("127.0.0.1:30302");
group = new NetGroup(nc, groupspec.groupspecWithAuthorizations());
group.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
}
private var i:int = 0;
private function sendMessage():void
{
var message:Object = new Object();
message.sender = group.convertPeerIDToGroupAddress(nc.nearID);
message.text = "Here's your message!";
message.random = i++;
group.post(message);
}
public function receiveMessage(message:Object):void
{
writeText(message.text);
}
private function writeText(txt:String):void
{
txtHistory.text += txt + "\n";
}
private function btnSend_clickHandler(event:MouseEvent):void
{
sendMessage();
}
]]>
</fx:Script>
<s:layout>
<s:VerticalLayout/>
</s:layout>
<s:TextArea id="txtHistory"
width="100%" height="100%"/>
<s:Button id="btnSend"
enabled="{connected}"
label="Send message"
click="btnSend_clickHandler(event)"/>
</s:WindowedApplication>
RTMFP2:
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
applicationComplete="connect()">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
private var nc:NetConnection;
private var group:NetGroup;
[Bindable]
private var connected:Boolean = false;
private function connect():void
{
nc = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
nc.connect("rtmfp:");
}
private function netStatus(event:NetStatusEvent):void
{
switch (event.info.code)
{
case "NetConnection.Connect.Success":
setupGroup();
break;
case "NetGroup.Connect.Success":
connected = true;
break;
case "NetGroup.Posting.Notify":
receiveMessage(event.info.message)
break;
}
}
private function setupGroup():void
{
var groupspec:GroupSpecifier = new GroupSpecifier("myGroup/groupOne");
groupspec.postingEnabled = true;
groupspec.ipMulticastMemberUpdatesEnabled = true;
groupspec.addIPMulticastAddress("127.0.0.1:30302");
group = new NetGroup(nc, groupspec.groupspecWithAuthorizations());
group.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
}
private var i:int = 0;
private function sendAcknowledge():void
{
var message:Object = new Object();
message.text = "We received your message!";
message.sender = group.convertPeerIDToGroupAddress(nc.nearID);
message.sequence = i++;
group.post(message);
}
public function receiveMessage(message:Object):void
{
writeText(message.text);
sendAcknowledge();
}
private function writeText(txt:String):void
{
textArea.text += txt + "\n";
}
]]>
</fx:Script>
<s:layout>
<s:VerticalLayout/>
</s:layout>
<s:TextArea id="textArea" width="100%" height="100%"/>
</s:WindowedApplication>
這些應用程序可以連接併發送消息給對方不會有問題在Windows XP上。但是,在Windows 7上,他們不能。
有誰知道爲什麼這不會在Windows 7上工作,以及可以採取哪些措施使其工作?這對我們的項目至關重要。在某些情況下,應用程序需要相當長的時間才能將相互檢測爲鄰居(某些情況下最多15秒),而在其他情況下,它們會立即檢測到對方。有誰知道什麼可能會導致這種延遲?
我建議使用wireshark進行調試(適當過濾掉協議,源和目的地,以避免看到所有額外的數據包),以查看XP和7之間從結尾處發生的情況。 – shaunhusain 2012-03-01 18:32:37