Exemplo n.º 1
0
 /**
  * Start server
  *
  * @param   string[] args
  */
 public static function main(array $args)
 {
     $stor = new TestingStorage();
     $stor->add(new TestingCollection('/', $stor));
     $stor->add(new TestingCollection('/.trash', $stor));
     $stor->add(new TestingElement('/.trash/do-not-remove.txt', $stor));
     $stor->add(new TestingCollection('/htdocs', $stor));
     $stor->add(new TestingElement('/htdocs/file with whitespaces.html', $stor));
     $stor->add(new TestingElement('/htdocs/index.html', $stor, "<html/>\n"));
     $stor->add(new TestingCollection('/outer', $stor));
     $stor->add(new TestingCollection('/outer/inner', $stor));
     $stor->add(new TestingElement('/outer/inner/index.html', $stor));
     $auth = newinstance('lang.Object', array(), '{
     public function authenticate($user, $password) {
       return ("testtest" == $user.$password);
     }
   }');
     $protocol = newinstance('peer.ftp.server.FtpProtocol', array($stor, $auth), '{
     public function onShutdown($socket, $params) {
       $this->answer($socket, 200, "Shutting down");
       $this->server->terminate= TRUE;
     }
   }');
     isset($args[0]) && $protocol->setTrace(Logger::getInstance()->getCategory()->withAppender(new FileAppender($args[0])));
     $s = new Server('127.0.0.1', 0);
     try {
         $s->setProtocol($protocol);
         $s->init();
         Console::writeLinef('+ Service %s:%d', $s->socket->host, $s->socket->port);
         $s->service();
         Console::writeLine('+ Done');
     } catch (Throwable $e) {
         Console::writeLine('- ', $e->getMessage());
     }
 }
Exemplo n.º 2
0
 /**
  * Main
  *
  * @param   string[] args
  * @return  int
  */
 public static function main(array $args)
 {
     Console::writeLinef('XP %s { PHP %s & ZE %s } @ %s', xp::version(), phpversion(), zend_version(), php_uname());
     Console::writeLine('Copyright (c) 2001-2013 the XP group');
     foreach (ClassLoader::getLoaders() as $delegate) {
         Console::writeLine($delegate->toString());
     }
     return 1;
 }
Exemplo n.º 3
0
 /**
  * Start server
  *
  * @param   string[] args
  */
 public static function main(array $args)
 {
     $s = new Server('127.0.0.1', 0);
     try {
         $s->setProtocol(XPClass::forName($args[0])->newInstance());
         $s->init();
         Console::writeLinef('+ Service %s:%d', $s->socket->host, $s->socket->port);
         $s->service();
         Console::writeLine('+ Done');
     } catch (Throwable $e) {
         Console::writeLine('- ', $e->getMessage());
     }
 }
Exemplo n.º 4
0
    /**
     * Start server
     *
     * @param   string[] args
     */
    public static function main(array $args)
    {
        // Add shutdown message handler
        EascMessageFactory::setHandler(61, newinstance('remote.server.message.EascMessage', array(), '{
        public function getType() { 
          return 61; 
        }
        public function handle($protocol, $data) {
          Logger::getInstance()->getCategory()->debug("Shutting down");
          $protocol->server->terminate= TRUE; 
        }
      }')->getClass());
        $s = new Server('127.0.0.1', 0);
        try {
            $protocol = new EascProtocol(newinstance('remote.server.deploy.scan.DeploymentScanner', array(), '{
          private $changed= TRUE;

          public function scanDeployments() {
            $changed= $this->changed;
            $this->changed= FALSE;
            return $changed;
          }

          public function getDeployments() {
            $res= "net/xp_framework/unittest/remote/deploy/beans.test.CalculatorBean.xar";

            with ($d= new Deployment($res)); {
              $d->setClassLoader(new ArchiveClassLoader(new Archive(ClassLoader::getDefault()->getResourceAsStream($res))));
              $d->setImplementation("beans.test.CalculatorBeanImpl");
              $d->setInterface("beans.test.Calculator");
              $d->setDirectoryName("xp/test/Calculator");

              return array($d);
            }
          }
        }'));
            $protocol->initialize();
            $s->setProtocol($protocol);
            $s->init();
            Console::writeLinef('+ Service %s:%d', $s->socket->host, $s->socket->port);
            $s->service();
            Console::writeLine('+ Done');
        } catch (Throwable $e) {
            Console::writeLine('- ', $e->getMessage());
        }
    }
Exemplo n.º 5
0
 public function writeLinef()
 {
     Console::writeLinef('Hello %s', 'World');
     $this->assertEquals("Hello World\n", $this->streams[1]->getBytes());
 }
Exemplo n.º 6
0
 /**
  * Start server
  *
  * @param   string[] args
  */
 public static function main(array $args)
 {
     $protocol = newinstance('peer.server.ServerProtocol', array(), '{
     public function initialize() { }
     public function handleDisconnect($socket) { }
     public function handleError($socket, $e) { }
     public function handleConnect($socket) { }
     
     public function handleData($socket) {
       $cmd= $socket->readLine();
       switch (substr($cmd, 0, 4)) {
         case "ECHO": {
           $socket->write("+ECHO ".substr($cmd, 5)."\\n"); 
           break;
         }
         case "LINE": {
           sscanf(substr($cmd, 5), "%d %s", $l, $sep);
           for ($i= 0, $sbytes= urldecode($sep); $i < $l; $i++) {
             $socket->write("+LINE ".$i.$sbytes); 
           }
           $socket->write("+LINE .\\n");
           break;
         }
         case "CLOS": {
           $socket->close(); 
           break;
         }
         case "HALT": {
           $socket->write("+HALT\\n"); 
           $this->server->terminate= TRUE; 
           break;
         }
       }
     }
   }');
     $s = new Server('127.0.0.1', 0);
     try {
         $s->setProtocol($protocol);
         $s->init();
         Console::writeLinef('+ Service %s:%d', $s->socket->host, $s->socket->port);
         $s->service();
         Console::writeLine('+ Done');
     } catch (Throwable $e) {
         Console::writeLine('- ', $e->getMessage());
     }
 }