open() public method

public open ( $timeOut = null )
示例#1
0
 public function openConnection()
 {
     $this->client->open();
     if (false !== ($this->webhooksConfig = $this->getWebhooksSettings())) {
         $this->startWebserver($this->webhooksConfig);
         $this->socket->listen($this->socketPort, $this->socketHost);
     }
     $this->loop->run();
 }
示例#2
0
 public function receive(callable $callback, callable $error)
 {
     $should_close = false;
     $this->client->on('request', function () {
         $this->logger->notice('Request object created!');
     });
     $this->client->on('handshake', function () {
         $this->logger->notice('Handshake received!');
     });
     $this->client->on('connect', function () {
         $this->logger->notice('Connected!');
     });
     $this->client->on('error', function () use($error) {
         // Call the error callback.
         $error();
         // Reopen the connection.
         $this->client->close();
         $this->client->open(self::TIMEOUT);
     });
     $this->client->on('close', function () use($should_close) {
         // Reopen the connection.
         if (!$should_close) {
             $this->client->open(self::TIMEOUT);
         }
     });
     $this->client->on('message', function (WebSocketMessageInterface $message) use($callback, &$should_close) {
         // Wait for the message to be finalized.
         if (!$message->isFinalised()) {
             return;
         }
         // Get the contents.
         $contents = json_decode($message->getData(), true);
         if (!$contents) {
             return;
         }
         // Handle the contents.
         $value = $this->handleContents($contents);
         // Call the callback with the value.
         $result = $callback($value);
         // If the callback returns true, close the connection.
         if ($result === true) {
             $should_close = true;
             $this->client->close();
         }
     });
 }
示例#3
0
 public function open($timeOut = null)
 {
     $promise = parent::open($timeOut);
     $this->on("connect", function () {
         $this->stream->on('close', function () {
             $this->emit('close');
         });
     });
     return $promise;
 }
 public function run()
 {
     while (true) {
         try {
             $this->loadAddresses();
             //aby načetl nově generované adresy
             $this->client->open();
             $this->loop->run();
         } catch (\Exception $e) {
             $this->logger->err($e->getMessage());
         }
     }
 }
示例#5
0
 function test_DoubleEchoResourceHandlerResponse()
 {
     $input = str_repeat("a", 1024);
     $input2 = str_repeat("b", 1024);
     $msg = WebSocketMessage::create($input);
     $client = new WebSocket("wss://127.0.0.1:12345/echo/");
     $client->setTimeOut(1000);
     $client->open();
     $client->sendMessage($msg);
     $client->sendMessage(WebSocketMessage::create($input2));
     $msg = $client->readMessage();
     $msg2 = $client->readMessage();
     $client->close();
     $this->assertEquals($input, $msg->getData());
     $this->assertEquals($input2, $msg2->getData());
 }
示例#6
0
 /**
  * Connect and start the event loop
  */
 public function run()
 {
     $this->wsClient->open();
     $this->eventLoop->run();
 }