Nats\Connection::connect PHP Method

connect() public method

Connect to server.
public connect ( float $timeout = null ) : void
$timeout float Number of seconds until the connect() system call should timeout.
return void
    public function connect($timeout = null)
    {
        if ($timeout === null) {
            $timeout = intval(ini_get('default_socket_timeout'));
        }
        $this->timeout = $timeout;
        $this->streamSocket = $this->getStream($this->options->getAddress(), $timeout);
        $this->setStreamTimeout($timeout);
        $msg = 'CONNECT ' . $this->options;
        $this->send($msg);
        $connect_response = $this->receive();
        if (strpos($connect_response, '-ERR') !== false) {
            throw new \Exception("Failing connection: {$connect_response}");
        }
        $this->ping();
        $ping_response = $this->receive();
        if ($ping_response !== "PONG") {
            if (strpos($ping_response, '-ERR') !== false) {
                throw new \Exception("Failing on first ping: {$ping_response}");
            }
        }
    }