我们在这个项目上遇到了一个奇怪的问题。当我们将NetConnection与NetGroup结合使用以启动Windows XP上两个本地AIR应用程序之间的通信时,它们总是成功连接到NetGroup并相互检测为邻居。但是,在Windows 7上,两个应用程序连接成功连接到NetConnection和NetGroup都不会将对方检测为邻居。
要重现此问题,以下是两个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以及可以采取哪些步骤来使其工作?这对我们的项目至关重要。
P.s。:在某些情况下,应用程序需要相当长的时间来检测彼此作为邻居(在某些情况下最多15秒),在其他情况下,它们会立即相互检测到。有谁知道什么可能导致这种延迟?
答案 0 :(得分:0)
我的第一个猜测是使用防火墙或网络。 RTMFP使用 UDP port 1935是非标准的,许多企业级防火墙阻止了非端口80或443(HTTP,HTTPS)的所有内容。
这就是为什么如果p2p不起作用,建议你有第三方服务器后备,因为情况并非总是如此。