PDA

View Full Version : Flash/XMLSocket in PHP?



Flashfortitude
10 Apr 2010, 06:07 PM
Hello there!
I'm new to the forums, so please be patient with me! :)

I've been trying to master the concept of "Sockets" to use in compliance with Flash to create multiplayer applications. I've been able to create a socket in PHP, and I can connect to it with Flash. However, when I try to read/write data, I get an IOError, and I have no idea why. The PHP connects and begins listening correctly, but it makes Flash throw an error. Here is the PHP code, with the IP set as my website's IP address:


<?php
$port = 5743;
$ip = '69.175.104.162';

set_time_limit(0);

$socket = socket_create(AF_INET, SOCK_STREAM, getprotobyname(TCP)) or die("Socket creation failed.");

echo'socket created!', "<br/>";

socket_bind($socket, $ip, $port) or die("Failed to bind to socket.");

echo'socket bound!<br/>';

socket_listen($socket) or die("Could not begin listening.<br/>");
echo'socket listening...<br/>';

$comm = socket_accept($socket) or die("Could not accept incoming connections.");

echo'communitcation socket established.<br/>';

$input = socket_read($comm) or die("Input reading failed.");

socket_write($comm, $input) or die("Could not write data.");

socket_close($comm);
echo'comm link closed.';
socket_close($socket);
echo'main socket closed.';
?>


And here's the Flash code, programmed from the timeline:


var mysocket:XMLSocket = new XMLSocket();

mysocket.connect("flashfortitude.com", 5743);

mysocket.send("Hello!");

mysocket.addEventListener(DataEvent.DATA, handledata);
mysocket.addEventListener(IOErrorEvent.IO_ERROR, handleio);


function handledata(e:DataEvent) {
trace(e);
}

function handleio(e:IOErrorEvent) {
trace("IO Error encountered. Still don't know what the beans that means.");
}