1. $buf=$buf . "\0";
2. security issue (port number beneath 1024 or anything else)
> There is a good tutorial of XMLsockets interacting with Php at
>
http://www.kirupa.com/developer/flash8/php5sockets_flash8_3.htm. >
> But, like all XMLSocket tutorials I've seen it distributes server-bound
> messages to all connected clients. My needs are much simpler: I just want to
> write data to connected sockets periodically.
>
> I've tried this by starting with the tutorial code. I've left the Flash code
> exactly the same and simplified the Php code as shown below. BTW, I use Flash
> 8, Php v. 5.1.4 and the original tutorial code itself works fine.
>
> The result of my changes is that I get the sockets set up (i.e. both the Flash
> OnConnect and the Php Activate say it is set up. When I write to Flash from
> Php, the code SAYS its succesful. But, I never see any text in the Flash app,
> nor is OnData ever triggered. Please tell me what silly thing I am doing:
>
>
>
> #!/usr/bin/php -q
> <?php
> error_reporting(E_ALL);
> set_time_limit(0);
> ob_implicit_flush();
> $address = "xx.xx.xx.xx"; //the ip address (and port) of the server- same as
> indicated in client software
> $port = "9xxx";
>
> //---- Function to Send out Messages ----------------------------------------
>
> function send_Message($client, $socket, $buf) {
> $buf="<xml><title> this is the title </title></xml>";
> $buf=$buf . '\u0000'; //I've also tried 0X00, NULL, "" and 0 as a terminator
> $len = strlen($buf);
> $numwrite=socket_write($client, "$socket wrote: $buf", $len);
> print $numwrite . "\n";
> print socket_strerror(socket_last_error()) . "\n"; //this is what tells me the
> write "is considered" to be a success
> }
> //---- Start Socket creation for PHP 5 Socket Server
> -------------------------------------
> if (($master = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) < 0) {
> echo "socket_create() failed, reason: " . socket_strerror($master) . "\n";
> }
> socket_set_option($master, SOL_SOCKET,SO_REUSEADDR, 1);
>
> if (($ret = socket_bind($master, $address, $port)) < 0) {
> echo "socket_bind() failed, reason: " . socket_strerror($ret) . "\n";
> }
>
> if (($ret = socket_listen($master, 5)) < 0) {
> echo "socket_listen() failed, reason: " . socket_strerror($ret) . "\n";
> }
>
> //---- accept connect request from Flash app ---------------------
> $currenttime=time();
> $starttime=time();
> if (($client = socket_accept($master)) < 0) {
> echo "socket_accept() failed: reason: " . socket_strerror($msgsock) . "\n";
> continue;
> }
> //---- Create Persistent Loop to write messages every 15 sec
> ---------------------
> while (true) {
>
> if (($currenttime - $starttime) > 15) {
> send_Message($client, $client, "show this message" );
> $currenttime=time();
> $starttime=time();
> } else {
> $currenttime=time();
> }
> }
>
> ?>