Results 1 to 2 of 2

Thread: flash+php socket problem!!

  1. #1

    flash+php socket problem!!

    hey guys..
    i prblm i was facing in php socket file is now solved, i m able to establsh the server connection with socket, but whn i send data or recv ne data thrs no effct, sumtimes i get that xml file of policy file which i m declaring in php(shell script) socket server file.
    my php shell script is:
    --------------------------------------
    #!/usr/bin/php -q
    <?php

    /**
    * @author Hiren Dave
    * @copyright 2009
    */

    error_reporting(E_ALL);

    set_time_limit(0);

    ob_implicit_flush();

    $address = '127.0.0.1';
    $port = 9999;


    function send_Message($allclient,$buf)
    {
    foreach($allclient as $client)
    {
    socket_write($client, $buf.chr(0));

    }
    }

    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, 25)) < 0)
    {
    echo "socket_listen() failed, reason: " . socket_strerror($ret) . "\n";
    }

    $read_sockets = array($master);

    $policy_file =
    '<'.'?xml version="1.0" encoding="UTF-8"?'.'>'.
    '<cross-domain-policy xmlnssi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.adobe.com/xml/schemas/PolicyFileSocket.xsd">'.
    '<allow-access-from domain="*" to-ports="*" secure="false" />'.
    '<site-control permitted-cross-domain-policies="master-only" />'.
    '</cross-domain-policy>';
    //---- Create Persistent Loop to continuously handle incoming socket messages ---------------------
    while (true)
    {
    $changed_sockets = $read_sockets;
    $num_changed_sockets = socket_select($changed_sockets, $write = NULL, $except = NULL, NULL);
    foreach($changed_sockets as $socket)
    {
    if ($socket == $master)
    {
    if (($client = socket_accept($master)) < 0)
    {
    echo "socket_accept() failed: reason: " . socket_strerror($msgsock) . "\n";
    continue;
    }
    else
    {
    array_push($read_sockets, $client);
    socket_write($client, $policy_file.chr(0));

    }
    }
    else
    {
    $bytes = socket_recv($socket, $buffer, 2048, 0);
    if ($bytes == 0)
    {
    $index = array_search($socket, $read_sockets);
    unset($read_sockets[$index]);
    socket_close($socket);
    }
    else
    {

    $allclients = $read_sockets;
    array_shift($allclients);
    send_Message($allclients,$buffer);
    }
    }
    }
    }
    ?>
    -------------------------------------------------------
    and in flash:
    ----------------------------
    function sendData(player_id:Number)
    {
    var myXML:XML = new XML();
    var mysend = myXML.createElement("MESSAGE");
    mysend.attributes.playerid = player_id;
    myXML.appendChild(mysend);
    myXMLSocket.send(myXML);
    }
    myXMLSocket.onXML = myOnXML
    function myOnXML(doc)
    {
    var e = doc.firstChild;
    player_5.text = "myonxml";
    player_4.text = doc;
    if (e != null && e.nodeName == "MESSAGE")
    {
    player_5.text = "if";
    displayMessage(e.attributes.player_id);
    }
    }


    function displayMessage(msg:Number)
    {
    player_5.text = msg;
    }

    sendData(player_id);
    --------------------------------------------
    plz if possbl help me..
    Last edited by yagnesh; July 28th, 2009 at 07:46 AM. Reason: modifications

  2. #2
    problem solved!!!!!!!!!!!!! VIOLAAAAAAAAAAAAAAAAa!!!!!!!!!!!
    change flash code to :
    --------------------
    myXMLSocket.onXML = function(myXML:XML)
    {
    var e = myXML.firstChild;

    if (e != null && e.nodeName == "MESSAGE")
    {

    pid = e.attributes.msg;
    updateName(pid);
    }
    };
    function msgGO(player_id:Number)
    {

    var myXML:XML = new XML();
    var mysend = myXML.createElement("MESSAGE");
    mysend.attributes.msg = player_id;
    myXML.appendChild(mysend);
    myXMLSocket.send(myXML);

    }
    msgGO(player_id);
    -----------------------------
    the problem was in
    --------------
    function myOnXML(doc)
    {
    var e = doc.firstChild;
    player_5.text = "myonxml";
    player_4.text = doc;
    if (e != null && e.nodeName == "MESSAGE")
    {
    player_5.text = "if";
    displayMessage(e.attributes.player_id);
    }
    }
    -------------------

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012