Exemplo n.º 1
0
 /**
  * @param string $host
  * @param string $port
  * @param string $ticket
  */
 public function init($host, $port, $ticket)
 {
     $httpRequest = $this->buildRequest($ticket);
     $this->socket->create(AF_INET, SOCK_STREAM, SOL_TCP);
     $this->socket->connect(gethostbyname($host), $port);
     $this->socket->write($httpRequest, strlen($httpRequest));
     if (($status = $this->socket->read(self::FITNESSE_INTEGER)) != 0) {
         $errorMsg = $this->socket->read($status);
         $this->socket->close();
         throw new Exception("init() failed: " . $errorMsg . "\n");
     }
 }
Exemplo n.º 2
0
 /**
  * Connect to Kafka via a socket
  * 
  * @return void
  * @throws \Kafka\Exception
  */
 public function connect()
 {
     if (null === $this->socket) {
         $this->socket = new Socket($this->host, $this->port, $this->recvTimeoutSec, $this->recvTimeoutUsec, $this->sendTimeoutSec, $this->sendTimeoutUsec);
     }
     $this->socket->connect();
 }
 public static function shutdownApplicationServer()
 {
     self::$clientClassesLoader && ClassLoader::removeLoader(self::$clientClassesLoader);
     // Send shutdown message (this is not supported by live servers
     // but functionality added via EascMessageFactory::setHandler())
     try {
         $s = new Socket(self::$bindAddress[0], self::$bindAddress[1]);
         $s->connect();
         $s->write(pack('Nc4Na*', DEFAULT_PROTOCOL_MAGIC_NUMBER, 1, 0, 61, FALSE, 0, NULL));
         $s->close();
     } catch (Throwable $e) {
         // Fall through, below should terminate the process anyway
     }
     $status = self::$serverProcess->out->readLine();
     if (!strlen($status) || '+' != $status[0]) {
         while ($l = self::$serverProcess->out->readLine()) {
             $status .= $l;
         }
         while ($l = self::$serverProcess->err->readLine()) {
             $status .= $l;
         }
         self::$serverProcess->close();
         throw new IllegalStateException($status);
     }
     self::$serverProcess->close();
 }
 /**
  * Forces the server to refresh its configuration.
  *
  * @since 5.1
  * @return string Server result string.
  */
 public function refresh()
 {
     try {
         $result = '';
         $auth = ModuleServerAuthenticator::instance('ModuleServerAuthenticator');
         $this->socket->connect($this->host, $this->port);
         $request = 'REFRESH Module/1.0' . "\r\n";
         $request .= 'User: admin' . "\r\n";
         $request .= 'Password: '******'admin') . "\r\n";
         $this->socket->write($request);
         $result = $this->socket->readAll();
         $this->socket->disconnect();
     } catch (\Innomatic\Net\Socket\SocketException $e) {
         $result = 'Module server is down.' . "\n";
     }
     return $result;
 }
Exemplo n.º 5
0
 /**
  * force the ModuleServiceSocketHandler to refresh the registry
  *
  * @since 5.1
  */
 protected function force_refresh()
 {
     print "force_refresh" . "\n";
     $request = '';
     $address = '127.0.0.1';
     $context = \Innomatic\Module\Server\ModuleServerContext::instance('\\Innomatic\\Module\\Server\\ModuleServerContext');
     try {
         $port = $context->getConfig()->getKey('service_port');
         $this->socket->connect($address, $port);
         $request = 'REFRESH Module/1.1' . "\r\n";
         $request .= 'User: admin' . "\r\n";
         $request .= 'Password: '******'admin') . "\r\n";
         $this->socket->write($request);
         $result = $this->socket->readAll();
         $this->socket->disconnect();
     } catch (\Innomatic\Net\Socket\SocketException $e) {
         print "Cannot refresh: server " . $address . ":" . $port . " down!" . "\n";
     }
     print $result;
 }
 public static function shutdownServer()
 {
     // Tell the server to shut down
     try {
         $c = new Socket(self::$bindAddress[0], self::$bindAddress[1]);
         $c->connect();
         $c->write("HALT\n");
         $c->close();
     } catch (Throwable $ignored) {
         // Fall through, below should terminate the process anyway
     }
     $status = self::$serverProcess->out->readLine();
     if (!strlen($status) || '+' != $status[0]) {
         while ($l = self::$serverProcess->out->readLine()) {
             $status .= $l;
         }
         while ($l = self::$serverProcess->err->readLine()) {
             $status .= $l;
         }
         self::$serverProcess->close();
         throw new IllegalStateException($status);
     }
     self::$serverProcess->close();
 }
Exemplo n.º 7
0
 /**
  * get broker broker connect
  *
  * @param string $host
  * @param null   $lockKey
  *
  * @return array
  * @access private
  */
 public function getStream($host, $lockKey = null)
 {
     if (!$lockKey) {
         $lockKey = uniqid($host);
     }
     list($hostname, $port) = explode(':', $host);
     // find unlock stream
     if (isset(self::$stream[$host])) {
         foreach (self::$stream[$host] as $key => $info) {
             if ($info['locked']) {
                 continue;
             } else {
                 self::$stream[$host][$key]['locked'] = true;
                 $info['stream']->connect();
                 return array('key' => $key, 'stream' => $info['stream']);
             }
         }
     }
     // no idle stream
     $stream = new Socket($hostname, $port, $this->getStreamOption('RecvTimeoutSec'), $this->getStreamOption('RecvTimeoutUsec'), $this->getStreamOption('SendTimeoutSec'), $this->getStreamOption('SendTimeoutUsec'));
     $stream->connect();
     self::$stream[$host][$lockKey] = array('locked' => true, 'stream' => $stream);
     return array('key' => $lockKey, 'stream' => $stream);
 }
Exemplo n.º 8
0
 public static function synchronizeInboundAltitude(IConnection $connect, $syncID, $userID)
 {
     global $database, $servers_altitude;
     $response = "";
     $path_data = PATHDATA_SOCKET_EASYLOAD;
     $path_file = "{$path_data}/{$userID}_{$syncID}";
     $output = "";
     try {
         //$objCampaign = Campaign::getCampaignByID($connect, $campaignID);
         //$shortname = $objCampaign->getShortName();
         //$objSync = new SynchronizeFolio($syncID,0, 0, "", "", "");
         $without_easycode = FolioImport::getRegistersInboundRegestion($connect, 'S');
         $action = 1;
         try {
             $objSocket = new Socket(IP_SOCKET_EASYLOAD, PORT_SOCKET_EASYLOAD, TIMEOUT_SOCKET_EASYLOAD);
             $objSocket->connect();
             // 1. Comprobando enlace con socket
             $objSocket->send("ACTION=TEST");
             $response = $objSocket->receive();
             //$objSync->updateSynchronizeAction($connect, $action, "OK");
             // 2. Generando archivo .TYP
             $action = 2;
             sleep(1);
             $filename = Util::generateFilesImportInbound($connect, $path_file, "TYP", true);
             //$objSync->updateSynchronizeAction($connect, $action, "OK");
             // 3. Generando archivo .dat
             $action = 3;
             sleep(1);
             Util::generateFilesImportInbound($connect, $path_file, "DAT", true);
             //$objSync->updateSynchronizeAction($connect, $action, "OK");
             // 4. Delegar a socket importar data en altitude
             $action = 4;
             sleep(1);
             $serverAtt = SERVER_NORMAL;
             //trim($objCampaign->getServerAltitude()) == "" ? SERVER_NORMAL : trim($objCampaign->getServerAltitude());
             $connectSQL = Util::createConnection(ENGINE_SQLSERVER, $database[$servers_altitude["{$serverAtt}"]['altitude']]);
             $connectSQL->connect();
             $rsDataAltitude = Altitude::getCampaignsByContactTable($connectSQL, 'outbound_retencion');
             $data = $connectSQL->getRows($rsDataAltitude);
             $campaignATT = trim($data['shortname']);
             $accessInstance = $database[$servers_altitude["{$serverAtt}"]['altitude']];
             $instance = $accessInstance['serverIA'] . ":" . $accessInstance['portIA'];
             $objSocket->send("ACTION=IMPORT;CAMPAIGN={$campaignATT};FILE={$filename};INSTANCE={$instance};USER={$userID};SYNCID={$syncID}");
             $response = $objSocket->receive();
             echo $response;
             /*if ($response == "ERROR" || $response == "WARN") {
                                 $msg = Util::getContentFile("{$path_file}/{$campaignATT}_messages.txt");
                                 $txt = "Ocurrio un problema en la importacion altitude";
                                 $mex = new MyException("$msg", 0, $txt);
                                 $mex->publisherSqlException(false);
                                 $mex->setText("{$txt}. Error# {$mex->getExceptionID()}");
                                 $output = "{$txt}. Error# {$mex->getExceptionID()}.";
             
                                 if ($response == "ERROR") {
                                     throw $mex;
                                 }
                             }*/
             //$objSync->updateSynchronizeAction($connect, $action, "{$response}");
             // 5. Finalizando enlace con socket
             $action = 5;
             $objSocket->changeTimeout(15);
             $objSocket->send("ACTION=END");
             $response = $objSocket->receive();
             //$objCampaign = Campaign::getCampaignByID($connect, $campaignID);
             //$objFolio = FolioImport::getFolioImport($connect, $folioID);
             //$total_folio = $objFolio->getRegistersImported();
             //$without_easycode = FolioImport::getRegistersWithoutEasycode($connect, $shortname, $folioID, 'S');
             //$objSync->updateSynchronizeAction($connect, $action, $total_folio - $without_easycode);
         } catch (MyException $ex) {
             $output = "ERROR: " . $ex->getText();
             //$objSync->updateSynchronizeAction($connect, $action, "ERROR: {$ex->getText()}");
         }
     } catch (MyException $ex) {
         $output = "Error: " . $ex->getText();
     }
     return $output;
 }
 public function connect(InetAddress $ipAddress, $portNumber)
 {
     $this->socket->connect($ipAddress, $portNumber);
 }
Exemplo n.º 10
0
 /**
  * Retrieve transfer socket
  *
  * @return  peer.Socket
  */
 public function transferSocket()
 {
     $port = $this->expect($this->sendCommand('PASV'), array(227));
     $a = $p = array();
     sscanf($port, '%*[^(] (%d,%d,%d,%d,%d,%d)', $a[0], $a[1], $a[2], $a[3], $p[0], $p[1]);
     // Open transfer socket
     $transfer = new Socket(implode('.', $a), $p[0] * 256 + $p[1]);
     $transfer->connect();
     return $transfer;
 }
Exemplo n.º 11
0
 /**
  * opens secure socket using ssl to this ip address
  *
  * @param   int       $port      port to connect to
  * @param   int       $timeout   optional  connection timeout
  * @param   callable  $openWith  optional  open port with this function
  * @return  \stubbles\peer\Stream
  */
 public function openSecureSocket(int $port, int $timeout = 5, callable $openWith = null) : Stream
 {
     $socket = new Socket($this->ip, $port, 'ssl://');
     if (null !== $openWith) {
         $socket->openWith($openWith);
     }
     return $socket->connect()->setTimeout($timeout);
 }
Exemplo n.º 12
0
 /**
  * @expectedException \Beanie\Exception\SocketException
  * @expectedExceptionCode -1
  */
 public function testReadLine_noMoreData_throwsException()
 {
     $this->_socketCreateSuccess();
     $this->_socketConnectSuccess();
     $this->_getNativeFunctionMock()->expects($this->once())->method('socket_read')->willReturn('');
     $socket = new Socket();
     $socket->connect();
     $socket->readLine();
 }
Exemplo n.º 13
0
ini_set('default_socket_timeout', -1);
if ($argc < 3) {
    echo "php benchmark.php host port [startUserId] [userCount] [executeTime]\n";
    exit(0);
}
Gbl::$host = $argv[1];
Gbl::$port = intval($argv[2]);
Gbl::$uidIndex = isset($argv[3]) ? intval($argv[3]) : 30000;
Gbl::$userCount = isset($argv[4]) ? intval($argv[4]) : 10;
Gbl::$executeTime = isset($argv[5]) ? intval($argv[5]) : 60;
Gbl::init();
// real do
for ($i = 0; $i < Gbl::$userCount; ++$i) {
    $user = Gbl::getUser();
    $socket = new Socket(Gbl::$host, Gbl::$port, $user['uid'], $user['account'], $user['password'], $user['groupId'], $user['chatroomId']);
    if ($socket->connect()) {
        Gbl::$fpList[] = $socket->fp;
        Gbl::$socketList[(int) $socket->fp] = $socket;
        $socket->sendAuthPacket();
    } else {
        echo "[ERROR] connect error user id {$user['uid']}\n";
    }
}
$second = 15;
echo "wait {$second} second\n";
sleep($second);
$start = time();
echo "go!!!\n";
while (true) {
    $readList = $writeList = $errorList = Gbl::$fpList;
    if (socket_select($readList, $writeList, $errorList, null) > 0) {
Exemplo n.º 14
0
 public function connect($address)
 {
     parent::connect($address);
 }