Scalalang2
Scalalang2

Reputation: 546

Connecting to TCP server from flash socket on local environment

I have made a swf file for distribution version to clients to use on their computer.
and I have a TCP server connected from that swf file.
before testing it, I have read some articles related to policy file on adobe website

I tried to test that, and have used the nodejs and swf file for that

but I failed. here is how it looks like.

crossdomain.xml on root

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
    <allow-access-from domain="*" to-ports="3000" />
</cross-domain-policy>

tcp_server.js

var sys = require("sys"),
net = require("net");

var server = net.createServer(function(stream) {
stream.addListener("connect", function() {
    sys.puts("Client connected");
    stream.write("hello\r\n");
});

stream.addListener("data", function(data) {
    sys.puts("Received from client: " + data);
    stream.write(data);
});

stream.addListener("end", function() {
    sys.puts("Client disconnected");
    stream.write("goodbye\r\n");
    stream.end();
});
});

server.listen(3000, "localhost");

swf file on local

import flash.net.Socket;

var socket:Socket = new Socket();
trace(socket);
trace("a socket is created");

socket.connect("localhost", 3000);

It seems like a long code, anyway

I tested it, and got this error

for wrong code, the policy file at xmlsocket://localhost:843 will be ignored

I can't find what is wrong with my code,
If you know that, Please let me know
Thanks for who reads this question

Have a nice day.

Upvotes: 2

Views: 4346

Answers (1)

Ilya Zaytsev
Ilya Zaytsev

Reputation: 1055

Flash Player checks for a policy file server (port 843 by default), or if necessary, on the socket you're opening (for you, port 3000).

A policy file server is a socket which responds to a with a valid policy file. What's happening with your message is likely that it's sending its request and getting something other than a policy file back, hence invalid syntax from port 3000. Programming socket to return your crossdomain.xml file over the socket when it got a <policy-file-request/> message.

more http://www.adobe.com/devnet/flashplayer/articles/socket_policy_files.html

Upvotes: 1

Related Questions