/** * @return Socket */ protected function connect() { // socket not yet connected? if (!$this->socket || !$this->socket->hasValidSocket()) { // create new socket wrapper instance $this->socket = new Socket(\socket_create(\AF_INET, \SOCK_STREAM, \SOL_TCP)); // bind and listen to socket $this->socket->bind($this->address, $this->port)->listen(); // (non) blocking mode? if (true === $this->isBlocking()) { $this->socket->setBlocking(); } else { $this->socket->setNonBlocking(); } } // return socket wrapper return $this->socket; }