Changeset 17

Show
Ignore:
Timestamp:
10/06/08 16:24:06 (6 weeks ago)
Author:
richard
Message:

Basic socket server

Location:
flashunity
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • flashunity/libraries/Flashunity/Base.php

    r12 r17  
    11<?php 
     2/** 
     3 * 
     4 * Extention to the Solar Cli library 
     5 * 
     6 * @category Main 
     7 * @package Flashunity 
     8 * @author Richard Thomas <richard@phpjack.com> 
     9 * @version $Id$ 
     10 * @copyright Copyright (c) 2008, Richard Thomas.  All rights reserved. 
     11 * @license http://www.phpjack.com 
     12 * @link http://www.phpjack.com 
     13 */ 
     14 
    215class Flashunity_Base extends Solar_Cli_Base { 
    316    protected $_Flashunity_Base = array( 
  • flashunity/libraries/Flashunity/Cli/Daemon.php

    r11 r17  
    11<?php 
     2/** 
     3 * 
     4 * Main daemon used to run the server 
     5 * 
     6 * @category Main       
     7 * @package Flashunity 
     8 * @author Richard Thomas <richard@phpjack.com> 
     9 * @version $Id$ 
     10 * @copyright Copyright (c) 2008, Richard Thomas.  All rights reserved.       
     11 * @license http://www.phpjack.com 
     12 * @link http://www.phpjack.com 
     13 */ 
    214 
    315 
    416class Flashunity_Cli_Daemon extends Flashunity_Base { 
    517    private $_tbalance_time = null; 
    6  
    718    public function __construct($config = null) { 
    819      parent::__construct($config); 
     
    1627        $config['transport'] = 'tcp';         
    1728        $config['port'] = '9997'; 
    18         $config['address'] = 'localhost'; 
     29        $config['address'] = '10.0.1.203'; 
    1930        $config['buffer'] = 1024; 
    2031        $this->_tbalance_time = microtime(1); 
     
    2435            $this->server->build_pool(); 
    2536            $this->server->check_pool(); 
    26             $this->server->check_new_conn(); 
    27             $this->server->check_new_data(); 
     37            if($new = $this->server->check_new_conn()) { 
     38                foreach($new as $value) { 
     39                    // $value = key we can use to reference for writes and such 
     40                    // We should record this and reference it 
     41                } 
     42            } 
     43            $data = $this->server->check_new_data(); 
     44            foreach($data as $key => $value) { 
     45                $test = array(); 
     46                $test[1] = 'Testing'; 
     47                $test[2] = 'Whats up'; 
     48                $test[3][1] = 'Go Go'; 
     49                $test[3][2] = 'On On'; 
     50                $this->server->write_all(json_encode($test)); 
     51                echo "Writing\n"; 
     52            } 
    2853            $this->_tbalance(); 
    2954        } 
     
    3762            usleep($this->_config['Performance']['Min_Time'] - $dtime); 
    3863        } else { 
    39             $this->log('Flashunity_Deamon',Flashunity_Base::NORMAL,'Ran past min performance time'); 
     64            $this->log('Flashunity_Deamon',Flashunity_Base::NORMAL,'Ran past min performance time by '.$dtime.' microseconds'); 
    4065        } 
     66        $this->_tbalance_time = microtime(1); 
    4167    } 
    4268 
  • flashunity/libraries/Flashunity/Cli/Daemon/Info/options.php

    r11 r17  
    11<?php 
     2 
    23return array( 
    34); 
  • flashunity/libraries/Flashunity/Cli/Help.php

    r11 r17  
    11<?php 
     2/** 
     3 * 
     4 * Simple Help Files 
     5 * 
     6 * @category Main       
     7 * @package Flashunity 
     8 * @author Richard Thomas <richard@phpjack.com> 
     9 * @version $Id$ 
     10 * @copyright Copyright (c) 2008, Richard Thomas.  All rights reserved.       
     11 * @license http://www.phpjack.com 
     12 * @link http://www.phpjack.com 
     13 */ 
    214 
    315class Flashunity_Cli_Help extends Flashunity_Base { 
  • flashunity/libraries/Flashunity/Comm/Socket.php

    r11 r17  
    11<?php 
    22/** 
    3  *  
    4  * @category Comm 
    5  * @package Main 
    6  * @author Richard Thomas <cyberlot[AT]cyberlot.net> 
    7  * @license http://www.cyberlot.net 
    8  *  
     3 * 
     4 * Extention to the Solar Cli library 
     5 * 
     6 * @category Main       
     7 * @package Flashunity 
     8 * @author Richard Thomas <richard@phpjack.com> 
     9 * @version $Id$ 
     10 * @copyright Copyright (c) 2008, Richard Thomas.  All rights reserved.       
     11 * @license http://www.phpjack.com 
     12 * @link http://www.phpjack.com 
    913 */ 
     14 
    1015class Flashunity_Comm_Socket extends FlashUnity_Base { 
    1116    private $resource = NULL; 
     
    2833     
    2934    public function check_new_data() { 
     35        $data = array(); 
    3036        while(list($key, $client) = each($this->cpool)) { 
    3137            if(!is_object($client) OR !$client->resource) { 
     
    3945                $rtval = $this->_read($client); 
    4046                if($rtval) { 
    41                     $this->_write_all($rtval); 
     47                    $data[$key] = $rtval; 
     48//                    $this->_write_all($rtval); 
    4249                } 
    4350            } 
    4451        } 
     52        return $data; 
     53    } 
     54     
     55    public function write($ckey, $string) { 
     56        $this->_write($this->cpool[$ckey], $string); 
     57    } 
     58     
     59    public function write_all($string) { 
     60        $this->_write_all($string); 
    4561    } 
    4662     
     
    7894            $this->cpool[$key]->key = $key; 
    7995        } 
     96        return $key; 
    8097    } 
    8198     
    8299    public function check_new_conn() { 
     100        $new = NULL; 
    83101        if(in_array($this->resource, $this->current)) { 
    84             $this->_accept_conn(); 
     102            $new[] = $this->_accept_conn(); 
    85103        } 
     104        return $new; 
    86105    } 
    87106 
  • flashunity/libraries/Flashunity/Transport/Xml.php

    r16 r17  
    11<?php 
    22/** 
    3  *  
    4  * @category Transport 
    5  * @package Main 
    6  * @author Richard Thomas <cyberlot[AT]cyberlot.net> 
    7  * @license http://www.cyberlot.net 
    8  *  
     3 * 
     4 * Extention to the Solar Cli library 
     5 * 
     6 * @category Main       
     7 * @package Flashunity 
     8 * @author Richard Thomas <richard@phpjack.com> 
     9 * @version $Id$ 
     10 * @copyright Copyright (c) 2008, Richard Thomas.  All rights reserved.       
     11 * @license http://www.phpjack.com 
     12 * @link http://www.phpjack.com 
    913 */ 
     14 
    1015class Flashunity_Transport_XML extends Solar_Cli_Base { 
    1116 
     
    1924 
    2025  public function read($client, $string) { 
    21     return $string; 
     26    return trim($string); 
    2227  } 
    2328} 
  • flashunity/script/flashunity.php

    r14 r17  
    11#!/usr/bin/php 
    22<?php 
     3/** 
     4 * 
     5 * @category Main       
     6 * @package Flashunity 
     7 * @author Richard Thomas <richard@phpjack.com> 
     8 * @version $Id$ 
     9 * @copyright Copyright (c) 2008, Richard Thomas.  All rights reserved.       
     10 * @license http://www.phpjack.com 
     11 * @link http://www.phpjack.com 
     12 */ 
     13 
    314error_reporting(E_ALL); 
    415// system trunk directory