Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

talking to Flash XMLsocket

Status
Not open for further replies.

afx

Programmer
Mar 4, 2004
27
CA
I have a very simple flash. It has a single layer:

layer 1: (ActionScript)
myXML = new XMLSocket;
myXML.onConnect = handleConnect;
myXML.onXML = handleXML;
myXML.onClose = handleDisconnect;
myXML.connect("localhost", 8090);

function handleConnect(connectionStatus){
connectionStatus ? trace("Connected.") : trace("Connection failed.");
myXML.send(new XML('"OKzap"'));
}

function handleXML(xmlObject){
var e = xmlObject.firstChild;
if (e != null && e.nodeName == "x") {
displayMessage(e.attributes.user, e.attributes.text);
}
trace("Object recieved:: "+xmlObject);
}

function sendXML(textToSend){
myXML.send(new XML('"+textToSend+"'));
}

function handleDisconnect(){
trace("Connection lost.");
}

function closeConnection(){
trace("Closing connection to server.");
myXML.close();
}

========================

I have some PHP that loads the SWF and tries to connect to it:

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase=" width="650" height="300">
<param name="movie" value="XMLsocket_test.swf">
<param name="quality" value="high">
<embed src="/kerrypress/XMLsocket_test.swf" quality="high" pluginspage=" type="application/x-shockwave-flash" width="650" height="100"></embed>
</object>
<?php
$status_flash = pfsockopen("localhost", 8090, $errno, $errdesc, 6);
if (! $status_flash) {
die("Could not connect to flash client:\nError: $errno = $errdesc\n");
}
fputs($status_flash, "<x>yahoo</x>\x00"); //send message
?>

================================

The error I'm getting is:
Warning: pfsockopen(): unable to connect to localhost:8090 in C:\Program Files\Apache Group\Apache2\htdocs\....\access.php on line 185
Could not connect to flash client: Error: 10060 = A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

My questions are these:
1. Do I call the SWF file first (<object> ... </object>) and THEN call the PHP pfsockopen() function or the other way around?
2. I've tried "localhost", the actual IP of my local machine (I'm trying to get this to run on my own machine before letting it loose on an external web server) - how do I address the port?

regards
Mark H., AFX
 
I forgot to say what it should do!

There is a text area that I would (eventually) like to output whatever message PHP has sent to it.

Another question: does the flash movie need to loop to constantly receive updates?

The idea is that the text area should contain the progress messages from a PHP process.

regards
Mark H., AFX
 
I am unsure if you understand how the flash socket works.
macromedia said:
To use the XMLSocket object, the server computer must run a daemon that understands the protocol used by the XMLSocket object.

You code connects to port 8090 from the flash and the PHP. That won't work. What you would have to do is have a command line PHP script that listens on the specific port. Writing such a daemon is not a trivial matter.

Have a look at this tutorial:
 
Thanks for the link. I've had success with sockets aimed at a Perl-based socket on a unix box and that works fine.

Does this mean that the XMLsocket in flash cannot RECEIVE messages - your reply implied that Flash had to talk PHP run on a command line.

All I want to do is have the user hit a button in a browser page that causes PHP to go through a set of steps (let's say they're called step 1, step 2, etc) and have the flash receive the messages "Step 1 done", "Step 2 done" etc and update the display as the messages arrive.

I can't believe I'm the only person who needs this sort of real-time feedback in a web page!!!

regards
Mark H., AFX
 
Lets think through this:

A flash movie is client side. It has no knowledge of ports, on the client. However, the socket connection is a bi-directional socket that allows the flash movie to send and receive XML messages with a server side daemon (written in any language).
In any case, the client initiated the socket connection.

You want to invoke a PHP script by pressing a button and have the flash update a message. Is the button in the movie?

I would do the following (no flash required):
execute the steps in an iframe within the page and display the resulting message within that iframe. Works great, I use it for scripts that have many steps and update the progress in the iframe.
Theoretically the returned content of the iframe could be scripted on the client side to talk to the flash in the page and update some content.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top