Exemplo n.º 1
0
 /**
  * @return $this
  * @throws ConnectionException
  * @throws ConnectionException
  */
 public function connect()
 {
     if (null === $this->socket) {
         // create socket
         $socket = \socket_create(\AF_INET, \SOCK_STREAM, \SOL_TCP);
         if (!$socket) {
             throw ConnectionException::socketError(\socket_strerror(\socket_last_error()));
         }
         // create socket wrapper
         $socket = new Socket($socket);
         $socket->connect($this->host, $this->port);
         // keep the socket
         $this->socket = $socket;
     }
     return $this;
 }