问题描述
我有,我想连接到服务器的Flash客户端。两者都是使用本地主机和端口50000所以不应该有任何跨域问题。我还设置只访问网络的发布设置。当我打电话的XMLSocket连接,服务器似乎得到一个新的连接。但是,该XMLSocket.onConnect回调不叫成功=正确的。
这是什么可能是错的任何想法?
下面的动作脚本创建套接字。
函数myOnConnect(成功){
如果(成功){
跟踪(连接成功!)
inputText.text =开放;
// socket.send(1 \ N);
的gotoAndPlay(2);
} 其他 {
跟踪(连接失败!)
inputText.text =失败;
}
}
btnConnect.onRelease =功能()
{
inputText.text =开始;
结果= socket.connect(本地主机,50000);
}
插座=新的XMLSocket();
socket.onConnect = myOnConnect;
这最终是一个安全问题。 Flash播放器增加了安全性时的XMLSocket使用。 Flash播放器现在看起来对端口843的策略文件另一种方法是要让SWF寻找使用呼叫在Security.loadPolicyFile()
政策文件。如果该文件存在,所有的安全设置允许使用XMLSocket,那么连接将被创建。
退房政策文件等详细信息 Adobe文章href="http://www.adobe.com/devnet/flashplayer/articles/fplayer9%5Fsecurity%5F05.html#%5FConfiguring%5FSocket%5FPolicy">here.这是一个有关政策文件另一篇好文章。
下面是最终为我工作的政策文件。它不是限制性的。但是,我想我得到的东西的工作,然后让他们正确的。
< XML版本=1.0&GT?;
<!DOCTYPE跨域政策体系/xml/dtds/cross-domain-policy.dtd">
!< - XMLSocket策略文件://socks.example.com - >
<交域政策>
<! - 这是一个主套接字策略文件 - >
<! - 在主机上没有其他插槽的政策将被允许 - >
<! - <现场控制允许交叉域策略=所有/> - >
<! - 而不是设置到端口=*的,管理员可以使用范围和逗号 - >
&所述;! - 这将允许访问端口123,456,457和458 - >
<允许存取来自域=*到端口=*安全=FALSE/>
< /跨域策略>
I have a Flash client that I want to connect to a server. Both are using localhost and port 50000 so there shouldn't be any cross-domain problems. I also set Access Network Only in the publishing settings. When I call the XMLSocket connect, the server seems to get a new connection. But, the XMLSocket.onConnect callback is not called with success=true.
Any ideas on what may be wrong?
Here's the ActionScript for creating the socket.
function myOnConnect(success) {
if (success) {
trace ("Connection succeeded!")
inputText.text = "open";
// socket.send("1\n");
gotoAndPlay(2);
} else {
trace ("Connection failed!")
inputText.text = "failed";
}
}
btnConnect.onRelease = function()
{
inputText.text = "started";
result = socket.connect("localhost", 50000);
}
socket = new XMLSocket();
socket.onConnect = myOnConnect;
This ended up being a security problem. The Flash Player has added security when a XMLSocket is used. The Flash Player now looks for a policy file on port 843. An alternative is to have the swf look for the policy file using the call Security.loadPolicyFile()
. If the file exists and all the security settings permit the XMLSocket, then the connection is created.
Check out the Adobe article on Policy files and more info here. This is another good article about policy files.
Here is the policy file that finally worked for me. It is not restrictive at all. But, I figured I get things working and then make them right.
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "/xml/dtds/cross-domain-policy.dtd">
<!-- Policy file for xmlsocket://socks.example.com -->
<cross-domain-policy>
<!-- This is a master socket policy file -->
<!-- No other socket policies on the host will be permitted -->
<!-- <site-control permitted-cross-domain-policies="all"/> -->
<!-- Instead of setting to-ports="*", administrator's can use ranges and commas -->
<!-- This will allow access to ports 123, 456, 457 and 458 -->
<allow-access-from domain="*" to-ports="*" secure="false"/>
</cross-domain-policy>
这篇关于Flash客户端的XMLSocket没有连接到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!