In AS3 how to make a socket connection - actionscript-3

i have a ServerSocket listening for a ServerSocketConnectEvent.CONNECT event.
serverSocket.bind( 80, "127.0.0.1" );
serverSocket.addEventListener( ServerSocketConnectEvent.CONNECT, onConnect );
serverSocket.listen();
which then listens for a ProgressEvent.SOCKET_DATA event.
private function onConnect( event:ServerSocketConnectEvent ):void
{
clientSocket = event.socket;
clientSocket.addEventListener( ProgressEvent.SOCKET_DATA, onClientSocketData );
}
private function onClientSocketData( event:ProgressEvent ):void
{
var buffer:ByteArray = new ByteArray();
clientSocket.readBytes( buffer, 0, clientSocket.bytesAvailable );
...
Then I'm sending a simple message "hello" from my client.
This works fine when i'm running my client from the IDE.
but when i run the same client as a SWF from my browser i get this message in my buffer:
""<policy-file-request/>""
I've tried trapping this response with code like:
if( buffer.toString().search( "policy-file-request" != -1 ))
{
var str:String = "<?xml version=\"1.0\"?><cross-domain-policy><allow-access-from domain=\"*\" to-ports=\"*\" /></cross-domain-policy>\0";
clientSocket.writeUTFBytes( str );
clientSocket.flush();
}
the code is called but it doesn't work. how do i make the connection?
Please help :)

You need to define a socket policy and serve that xml file to the Flash requests, i.e.
<?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-policy file -->
<site-control permitted-cross-domain-policies="master-only"/>
<!-- Instead of setting to-ports="*",
administrators can use ranges and commas -->
<!-- This will allow access to ports 123, 456, 457, and 458 -->
<allow-access-from domain="swf.example.com" to-ports="123,456-458" />
</cross-domain-policy>
With the introduction of Adobe Flash Player 9,0,124,0, Flash Player
will not make a socket connection directly to a server without first
obtaining explicit permission from that server. This will require some
systems and networks to open up ports or run new services in order to
support granting permission.
Full samples of policy and server setups at available from:
http://www.adobe.com/devnet/flashplayer/articles/socket_policy_files.html
Flash Player checks for a socket policy file in three places for each IP connection. The checks occur in the following order:
Flash Player first checks port 843 to determine if there is a socket master policy file. If there is no socket master policy file or the socket master policy file has a site-control tag specifying "all", then Flash Player proceeds to the next step. If the site-control tag has a value of "none", then the process stops and the socket is denied a connection.
If an ActionScript Security.loadPolicyFile() command exists within the SWF file, then the Flash Player runtime checks that location. Flash Player checks the destination of the loadPolicyFile() only after it has checked the master policy file on port 843 for permission to acknowledge other policy files. If the developer has not specified a loadPolicyFile() command, then Flash Player checks the destination port of the connection.
The destination port of the connection is the last check made by Flash Player. This check is only performed if the socket master policy file permits Flash Player to check additional locations. If Flash Player still cannot locate a policy file granting permission, then the socket connection is denied.

Related

axis2/c server could not be opened

I'm going to use axis2/c on windows to build a program, but when i click the "axis_http_server.exe" to start up the axis2/c server, nothing happened but a flashing window, i could't see the message "Started Simple Axis2 HTTP Server..." which was seen in the offical tutorial by apache, i've not changed anything but set the System's environment variable which was initial, so how can i open this?
i've turned to the directory axix2c/logs,the details in the axis2.log are as below:
....\src\core\deployment\conf_builder.c(903) Transport sender is NULL for transport http, unable to continue
....\src\core\deployment\conf_builder.c(262) Processing transport senders failed, unable to continue
....\src\core\deployment\dep_engine.c(752) Populating Axis2 Configuration failed
....\src\core\deployment\conf_init.c(64) Loading deployment engine failed for repository ../.
....\src\core\transport\http\receiver\http_receiver.c(126) unable to create private configuration contextfor repo path ../
....\src\core\transport\http\server\simple_axis2_server\http_server_main.c(215) Server creation failed: Error code: 103 :: Failed in creating DLL

How to use "telemetry.cfg" and ".telemetry.cfg" files with Adobe Scout

In the simplest language possible, can someone please explain...
the function of the "telemetry.cfg" file when debugging an application with Adobe Scout?
the function of the ".telemetry.cfg" file when debugging an application with Adobe Scout?
what TelemetryAddress is needed in each file
The only information I've found describing their functionality is very limited and I'm having trouble wrapping my head around these concepts.
Some notes for reference...
Example of "telemetry.cfg" file contents ("172.30.124.81" is the local IP of the machine running Scout):
TelemetryAddress = 172.30.124.81:7934
SamplerEnabled = false
CPUCapture = false
DisplayObjectCapture = false
Stage3DCapture = false
ScriptObjectAllocationTraces = false
And ".telemetry.cfg" could be the same except:
TelemetryAddress = localhost:7934
I've read this to be true:
7934 - Scout's default port
7935 - Flash Builder's default port
Please don't just post a link to the official Adobe documentation; I've read it numerous times.
The .telemetry.cfg and telemetry.cfg file formats are the same.
Either one is only used when enabling Scout options to profile a swf in a remote process (i.e. on a different PC). This configuration file is located on the PC that is running the swf in order to tell the Flash runtime where to send its telemetry data and which data that it should send.
There is an iOS & Android app for configuring AIR on the actual mobile devices and thus the telemetry.cfg/.telemetry.cfg file is not used.
telemetry.cfg is used to config Air (via FlashBuilder) for profiling Blackberry 10s over their USB connection. Same options in the '.telemetry.cfg', just the IP is a link-local IPv4 address (169.254.x.x). Blackberry 10s are at end of life for support for AIR and I personally have not developed for them.
So in the Scout preferences:
You can change the port number that Scout uses, and this port number has to match the one used in the .telemetry.cfg that is located on the remote PC.
The "Make the Flash Runtime on thus computer connect to Scout" option actually creates a temporary ./telemetry.cfg that exists only while Scout run and is picked up by the Flash runtimes/SWFs that you run so profiling is automatic.
TelemetryAddress in the file is the IP (or host name) of the PC that is running Scout and the port address has to match the one assigned in the Scout Preferences (default is 7934)

Flash Socket connection from SWF hosted by a browser

I am attempting to use TCP Socket from Flash ActionScript. I am using a standard example provided by Adobe. Here is the code:
// Load policy file from remote server.
Security.loadPolicyFile("http://" + serverURL + "/crossdomain.xml");
// Attempt to connect to remote socket server.
try {
msg("Trying to connect to " + serverURL + ":" + portNumber + "\n");
socket.connect(serverURL, portNumber);
} catch (error:Error) {
/*
Unable to connect to remote server, display error
message and close connection.
*/
msg(error.message + "\n");
socket.close();
}
My crossdomain.xml file located on port 80:
<cross-domain-policy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.adobe.com/xml/schemas/PolicyFileSocket.xsd">
<allow-access-from domain="*" to-ports="*"/>
</cross-domain-policy>
When I load application, I see in my inspector that it accesses the policy file successfully. However Event.CONNECT is never called. I have tried opening various different ports on various domains including same domain with no luck. Tried different policy files.
What am I missing?
If the allowscriptaccess is false you won't be able to bypass that so what you are missing is the adobe policy server.
http://vvowproject.googlecode.com/svn-history/r41/trunk/server/flashpolicyd.py
On the server open port 843 then use this command
sudo ./flashpolicyd.py --file=crossdomain.xml --port=843
here is the crossdomain.xml
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM
"http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<site-control permitted-cross-domain-policies="master-only"/>
<allow-access-from domain="*"/>
<allow-http-request-headers-from domain="*" headers="SOAPAction"/>
</cross-domain-policy>
This will definitely work, i tried it myself with your example.
This is what I know from using TCP/IP Sockets and XML. I've set up a Ruby server with a Flash client successfully, but want to know more about chat servers. I hope some of this is helpful.
You need a Daemon with Flash AS3. Here's the documentation.
http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000318.html
alt text http://www.ashcraftband.com/myspace/videodnd/daemonLil.jpg
To create a socket connection, you must create a server-side application to wait for the socket connection request and send a response to the SWF file. This type of server-side application can be written in a programming language such as Java, Python, or Perl. To use the XMLSocket class, the server computer must run a daemon that understands the protocol used by the XMLSocket class. The protocol is described in the following list:
• XML messages are sent over a full-duplex TCP/IP stream socket connection.
• Each XML message is a complete XML document, terminated by a zero (0) byte.
• An unlimited number of XML messages can be sent and received over a single XMLSocket connection.
Understanding the security changes in Flash Player 10
http://www.adobe.com/devnet/flashplayer/articles/fplayer10_security_changes_02.html
XML SECURITY POLICY
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM
"http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<site-control permitted-cross-domain-policies="master-only"/>
<allow-access-from domain="*"/>
<allow-http-request-headers-from domain="*" headers="SOAPAction"/>
</cross-domain-policy>
FLASH CLIENT
Remember to set Publish Settings to Access Network Only.
SERVER
Open a separate port for security policy, and keep it running in the background.

Flash+Node.JS+Socket.io stuck at handshake authorized

I'm writing a small game, socket-based obviously. Everything works fine when in localhost, but when I'm running .swf file from my dedicated server, and trying to connect to node.js server, connection is getting stuck at "handshake authorized":
info: Server starting...
info - socket.io started
info: Listening on port 4000
info: Server started.
debug - client authorized
info - handshake authorized _kqPhvoD6jYI-c1Gr7zu
And thats it.
Local SWF File -> Local Node.JS -> works.
Local SWF File -> Remote Node.JS -> works.
Remote SWF File -> Remote Node.js -> doesn't work.
Node version 0.10.12. It's not a firewall or antivirus. Tried running on different ports.
Code example:
//setup express for serving crossdomain on same port as game
var express=require('express');
var app=express();
app.get("/crossdomain.xml", onGetCrossdomain);
var server=require('http').Server(app);
//setup socket io
var socketIo=require('socket.io');
var io=socketIo.listen(server);
//listen on port
server.listen(currentPort);
console.log("Listening on port "+currentPort);
io.set('transports',
[
'flashsocket'
]);
io.sockets.on('connection', onConnection);
function onGetCrossdomain(req, res)
{
res.sendfile(__dirname+'/crossdomain.xml');
}
function onConnection(socket)
{
console.log("connected");
}
I've installed earlier version of node (0.8.25) using n - node version manager (https://npmjs.org/package/n), and everything started working fine. Thanks funseiki!

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.
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