Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / Flash / Data Integration / January 2007



Tip: Looking for answers? Try searching our database.

problem with xmlsockets and Php

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
levrek1 - 10 Jan 2007 15:29 GMT
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();
}
}

?>
Perry - 12 Jan 2007 13:41 GMT
i can only guess:

1. $buf=$buf . "\0";
2. security issue (port number beneath 1024 or anything else)

good luck!
perry

levrek1 schrieb:
> There is a good tutorial of XMLsockets interacting with Php at  
> http://www.kirupa.com/developer/flash8/php5sockets_flash8_3.htm.
[quoted text clipped - 68 lines]
>
>  ?>
levrek1 - 17 Jan 2007 23:24 GMT
Thats it ( $buf=$buf . "\0";).  I knew it was simple. Why do some php/flash examples add '\u0000' or ' 0X00'  ?  Thanks
levrek1 - 25 Jan 2007 19:00 GMT
OK, that was the answer for THAT question-- "\0" worked great. Thanks

NOW A NEW PROBLEM - I've put the .swf file into a browser and it no longer
works.  I've used the same exact swf and php code.  Both are in the same
directory on the same server (public_html on Linux).  Also, if I embed the .swf
in a web page, that file also is in the same directory (in other words, I don't
see an obvious violation of the sandbox thing).

I run the php on the server, just like before and then start the webpage .swf.
I get "Connection with Server Failed".

Please help again!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.