是什么阻碍了 NetStream.onPeerConnect 被触发?
我正在使用 Adobe Stratus(现已重命名为 Cirrus)来构建 p2p 应用程序。在应用程序内部,我使用了 NetStream.onPeerConnect 回调函数,并期望每次连接对等点时都会触发它。然而,我的朋友 A 总是失败,而奇怪的是,朋友 B 却成功地调用了该函数,没有任何问题。
我想知道这个问题的原因可能是什么?
以下是代码片段的样子。
首先,创建一个NetConnection。
netConnection = new NetConnection();
netConnection.addEventListener(NetStatusEvent.NET_STATUS, netConnectionHandler);
netConnection.connect(SERVER_ADDRESS+DEVELOPER_KEY);
其次,在NetConnection连接成功后创建NetStream。
private function netConnectionHandler(event:NetStatusEvent):void{
switch (event.info.code){
case "NetConnection.Connect.Success":
sendStream = new NetStream(netConnection, NetStream.DIRECT_CONNECTIONS);
sendStream.addEventListener(NetStatusEvent.NET_STATUS, netStreamHandler);
var sendObj:Object = new Object();
sendObj.onPeerConnect = function(subscriber:NetStream) : Boolean {
trace("[onPeerConnect] far id: " + subscriber.farID);
return true;
}
sendStream.client = sendObj;
sendStream.publish("file");
......
第三,这是我如何在两个同伴之间建立联系的方法,
receivedStream = new NetStream(netConnection, farId);
receivedStream.client = this;
receivedStream.addEventListener(NetStatusEvent.NET_STATUS, incomingStreamHandler);
receivedStream.play("file");
请帮助启发我。谢谢!
I'm using Adobe Stratus (now renamed to Cirrus) to build a p2p application. Inside the application, I used NetStream.onPeerConnect callback function and expected it to be triggered every time when a peer is connected. However, it always failed with my friend A while strangely friend B managed to have the function called without any problem.
I was wondering what could be the cause to this issue?
Here are how the code pieces look like.
First of all, create a NetConnection.
netConnection = new NetConnection();
netConnection.addEventListener(NetStatusEvent.NET_STATUS, netConnectionHandler);
netConnection.connect(SERVER_ADDRESS+DEVELOPER_KEY);
Secondly, create NetStream upon NetConnection successfully connected.
private function netConnectionHandler(event:NetStatusEvent):void{
switch (event.info.code){
case "NetConnection.Connect.Success":
sendStream = new NetStream(netConnection, NetStream.DIRECT_CONNECTIONS);
sendStream.addEventListener(NetStatusEvent.NET_STATUS, netStreamHandler);
var sendObj:Object = new Object();
sendObj.onPeerConnect = function(subscriber:NetStream) : Boolean {
trace("[onPeerConnect] far id: " + subscriber.farID);
return true;
}
sendStream.client = sendObj;
sendStream.publish("file");
......
Thirdly, here's how I build the connection between two peers
receivedStream = new NetStream(netConnection, farId);
receivedStream.client = this;
receivedStream.addEventListener(NetStatusEvent.NET_STATUS, incomingStreamHandler);
receivedStream.play("file");
Please help enlighten me. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
原来我的朋友 A 位于对称 NAT 后面。我正在考虑为我们设置一个 TURN 服务器来建立成功的连接。
It turns out my friend A is behind a symmetric NAT. I'm thinking to setup a TURN server for us to build a successful connection.