/**
  * 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 (\lang\Throwable $e) {
         Console::writeLine('- ', $e->getMessage());
     }
 }
 /**
  * Start server
  *
  * @param   string[] args
  */
 public static function main(array $args)
 {
     $s = new Server('127.0.0.1', 0);
     try {
         $s->setProtocol(\lang\XPClass::forName($args[0])->newInstance());
         $s->init();
         Console::writeLinef('+ Service %s:%d', $s->socket->host, $s->socket->port);
         $s->service();
         Console::writeLine('+ Done');
     } catch (\lang\Throwable $e) {
         Console::writeLine('- ', $e->getMessage());
     }
 }
    /**
     * Start server
     *
     * @param   string[] args
     */
    public static function main(array $args)
    {
        // Add shutdown message handler
        \remote\server\message\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 \\lang\\archive\\ArchiveClassLoader(new \\lang\\archive\\Archive(\\lang\\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 (\lang\Throwable $e) {
            Console::writeLine('- ', $e->getMessage());
        }
    }
 /**
  * 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 (\lang\Throwable $e) {
         Console::writeLine('- ', $e->getMessage());
     }
 }