Estos son los servicios en el comand line de php, segun el ejemplo es la forma correcta de usarlos:
Código PHP :
<?php // Get the flashpolicy.xml file so we can send it to the Flash Player $filename = "./flashpolicy.xml"; $content = file_get_contents($filename); // Create a socket that uses the IPv4 protocol over TCP. By changin the // parameters passed into the function we could create an IPv6 socket and/or // create a socet that would use UDP. $socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP); if (!is_resource($socket)) { echo 'Unable to create socket: '. socket_strerror(socket_last_error()) . PHP_EOL; } else { echo "Socket created.\n"; } // Next we bind to a specfic host and port. In this case, the port is 843 because // we're listening for Flash Player's policy file request. if (!socket_bind($socket, 'localhost', 843)) { echo 'Unable to bind socket: '. socket_strerror(socket_last_error()) . PHP_EOL; } else { echo "Socket bound to port 843.\n"; } // Once we successfully bind to the host and port, we can start listening for requests // from the client. if (!socket_listen($socket,SOMAXCONN)) { echo 'Unable to listen on socket: ' . socket_strerror(socket_last_error()); } else { echo "Listening on the socket.\n"; } while(true) { $connection = @socket_accept($socket); if ($connection){ echo "Client $connection connected!\n"; } else { echo "Bad connection."; } } ?>
y el otro
Código PHP :
<?php create_connection('localhost',1740); function create_connection($host,$port) { $socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP); if (!is_resource($socket)) { echo 'Unable to create socket: '. socket_strerror(socket_last_error()) . PHP_EOL; } else { echo "Socket created.\n"; } if (!socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1)) { echo 'Unable to set option on socket: '. socket_strerror(socket_last_error()) . PHP_EOL; } else { echo "Set options on socket.\n"; } if (!socket_bind($socket, $host, $port)) { echo 'Unable to bind socket: '. socket_strerror(socket_last_error()) . PHP_EOL; } else { echo "Socket bound to port $port.\n"; } if (!socket_listen($socket,SOMAXCONN)) { echo 'Unable to listen on socket: ' . socket_strerror(socket_last_error()); } else { echo "Listening on the socket.\n"; } while (true) { $connection = @socket_accept($socket); if($connection) { echo "Client $connection connected!\n"; send_data($connection); } else { echo "Bad connection."; } } } function send_data($connection) { echo $connection; // Create a number between 30 and 32 that will be our initial stock price. $stock_price = rand(30,32); while (true) { socket_write($connection,"$stock_price\n",strlen("$stock_price\n")); sleep(2); // Generate a random number that will represent how much our stock price // will change and then make that number a decimal and attach it to the // previous price. $stock_offset = rand(-50,50); $stock_price = $stock_price + ($stock_offset/100); echo "$stock_price\n"; } } ?>
y la policy esta asi:
Código ActionScript :
<?php create_connection('localhost',1740); function create_connection($host,$port) { $socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP); if (!is_resource($socket)) { echo 'Unable to create socket: '. socket_strerror(socket_last_error()) . PHP_EOL; } else { echo "Socket created.\n"; } if (!socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1)) { echo 'Unable to set option on socket: '. socket_strerror(socket_last_error()) . PHP_EOL; } else { echo "Set options on socket.\n"; } if (!socket_bind($socket, $host, $port)) { echo 'Unable to bind socket: '. socket_strerror(socket_last_error()) . PHP_EOL; } else { echo "Socket bound to port $port.\n"; } if (!socket_listen($socket,SOMAXCONN)) { echo 'Unable to listen on socket: ' . socket_strerror(socket_last_error()); } else { echo "Listening on the socket.\n"; } while (true) { $connection = @socket_accept($socket); if($connection) { echo "Client $connection connected!\n"; send_data($connection); } else { echo "Bad connection."; } } } function send_data($connection) { echo $connection; // Create a number between 30 and 32 that will be our initial stock price. $stock_price = rand(30,32); while (true) { socket_write($connection,"$stock_price\n",strlen("$stock_price\n")); sleep(2); // Generate a random number that will represent how much our stock price // will change and then make that number a decimal and attach it to the // previous price. $stock_offset = rand(-50,50); $stock_price = $stock_price + ($stock_offset/100); echo "$stock_price\n"; } } ?>
pues hasta ahora he podido pasar las policy por el puerto 843 y conectar socket de datos en el otro puerto especifico para datos, pero a la hora de mandar el servidor los datos al cliente, me da un error:
Código :
Warning: socket_write(): Unable to wirte to socket [0]: Se ha anulado una conexion establecida por el software en su equipo de host
Y de ahi no lo saco, en mi swf me sale un error #2048
Que estoy haciendo mal?
Ojala no les quite mucho su tiempo y me puedan echar mano, gracias!