View Full Version : Php Socket works on localhost but not on a real domain...
Soul814
April 8th, 2008, 08:22 PM
So following this tutorial (http://www.kirupa.com/developer/flash8/php5sockets_flash8.htm). I have it working on localhost. In the php server script I used the address "127.0.0.1" and in the flash file I changed the socket connect to null (mySocket.connect(null, 9999);), that way it will take the address of whatever the URL is.
Anyways, now I uploaded the same files to two of my domains. One is a third party hosting, while the other is a computer I have set up to be accessible on the web. The socket server seems to be running, yet when I go to the socket page, the connection fails. Any ideas? Is there some security thing I am not aware of?
Templarian
April 8th, 2008, 08:40 PM
Are you running it on the same domain if not I think you will need a crossdomain.xml file for flash 8.
http://livedocs.adobe.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00001621.html
If not then the smarter people will have to help.
Soul814
April 8th, 2008, 08:44 PM
Would this still be the case with flash 9? I am just trying to get this to work on flash 8, before migrating the flash code to flash 9. I am currently ssh into the computers and running the php socket servers off the computers. Then I am trying to access the flash page through my home computer.
Sirisian
April 8th, 2008, 08:54 PM
A policy file is required for flash to communicate to something other than localhost. You should be getting a "<policy-request/>" kind of string on your php server when a flash socket tries to connect. Check for that and have it notify you in some way. Your server must send a policy file. (read the security white pages) If you're not getting one then there's a problem with your PHP code. That will narrow down the problem a lot.
Also just make the switch to AS3 now rather than later. The Flash.Net.Socket is nice :)
Soul814
April 8th, 2008, 09:11 PM
That's the problem, when I try to access the flash file, I just get a connection failed and no errors are displayed on the php socket server.
I didn't want to migrate the code to AS3 as of yet because I can't get it working aside from localhost. I tried creating a policy file and throwing it into the same folder and I am still unsuccessful. Can anyone help me out directly, through an instant messaging program? I'd really like to get this working. Thanks.
Sirisian
April 8th, 2008, 10:41 PM
And your PHP server is listening on the same port as flash is trying to connect to? Hmm, not sure what to tell you.
You have to tell flash player to download the policy file. Either that or when you get the policy request (which you said you aren't getting) then you have to send it. If you send the policy file with the same socket as they connected with you'll need to have the server disconnect after you send it. Then the client will connect again and not send a policy file at which point you can have the client send anything you want (presumably the word "connect" or some message the server can understand to know that it has the policy file.
Soul814
April 9th, 2008, 07:40 PM
Yep, they are both listening off 1024. So I following the tutorial, these are the changes I made.
// path to the crossdomain xml
System.security.loadPolicyFile("http://www.mysite.com/crossdomain.xml");
mySocket = new XMLSocket();
mySocket.onConnect = function(success) {
if (success) {
msgArea.htmlText += "<b>Server connection established!</b>";
} else {
msgArea.htmlText += "<b>Server connection failed!</b>";
}
};
mySocket.onClose = function() {
msgArea.htmlText += "<b>Server connection lost</b>";
};
XMLSocket.prototype.onData = function(msg) {
msgArea.htmlText += msg;
};
// null so it connects to whatever my url address is
mySocket.connect(null, 1024);
//--- Handle button click --------------------------------------
function msgGO() {
if (inputMsg.htmlText != "") {
mySocket.send(inputMsg.htmlText+"\n");
inputMsg.htmlText = "";
}
}
pushMsg.onRelease = function() {
msgGO();
};
crossdomain.xml
<?xml version="1.0"?>
<cross-domain-policy>
<allow-access-from domain="*" />
</cross-domain-policy>
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.