Flash 客户端 XMLSocket 未连接到服务器
我有一个 Flash 客户端,我想连接到服务器。 两者都使用 localhost 和端口 50000,因此不应该有任何跨域问题。 我还在发布设置中设置了仅访问网络。 当我调用 XMLSocket connect 时,服务器似乎获得了一个新连接。 但是,当 success=true 时,不会调用 XMLSocket.onConnect 回调。
关于可能出什么问题有什么想法吗?
这是用于创建套接字的 ActionScript。
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;
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;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这最终成为一个安全问题。 当使用 XMLSocket 时,Flash Player 增加了安全性。 Flash Player 现在在端口 843 上查找策略文件。另一种方法是使用调用
Security.loadPolicyFile()
让 swf 查找策略文件。 如果该文件存在并且所有安全设置都允许 XMLSocket,则会创建连接。查看有关策略文件的 Adobe 文章和更多信息此处。 这是另一篇关于策略文件的好文章。
这是最终对我有用的策略文件。 它根本没有限制性。 但是,我想我应该先让事情运转起来,然后再把它们做好。
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.