Esempio n. 1
0
 /**
  * Start transport provider
  *
  * @param \Thruway\Peer\ClientInterface $client
  * @param \React\EventLoop\LoopInterface $loop
  */
 public function startTransportProvider(ClientInterface $client, LoopInterface $loop)
 {
     Logger::info($this, "Starting Transport");
     $this->client = $client;
     $this->loop = $loop;
     \Ratchet\Client\connect($this->URL, ['wamp.2.json'], [], $loop)->then(function (WebSocket $conn) {
         Logger::info($this, "Pawl has connected");
         $transport = new PawlTransport($conn, $this->loop);
         $transport->setSerializer(new JsonSerializer());
         $this->client->onOpen($transport);
         $conn->on('message', function ($msg) use($transport) {
             Logger::debug($this, "Received: {$msg}");
             try {
                 $this->client->onMessage($transport, $transport->getSerializer()->deserialize($msg));
             } catch (DeserializationException $e) {
                 Logger::warning($this, "Deserialization exception occurred.");
             } catch (\Exception $e) {
                 Logger::warning($this, "Exception occurred during onMessage: " . $e->getMessage());
             }
         });
         $conn->on('close', function ($conn) {
             Logger::info($this, "Pawl has closed");
             $this->client->onClose('close');
         });
     }, function ($e) {
         $this->client->onClose('unreachable');
         Logger::info($this, "Could not connect: {$e->getMessage()}");
     });
 }
Esempio n. 2
-4
 public function start(callable $onConnect)
 {
     \Ratchet\Client\connect($this->url)->then(function ($conn) use($onConnect) {
         $this->conn = $conn;
         $this->parseMessages();
         $onConnect();
     }, function (Exception $e) {
         $this->io->error('Error when trying to connect to the socket "' . $this->url . "\": {$e->getMessage()}\n");
         $this->stop();
     });
 }