JAXLSocketClient::connect PHP 메소드

connect() 공개 메소드

public connect ( string | resource $socket_path )
$socket_path string | resource
    public function connect($socket_path)
    {
        if (gettype($socket_path) == "string") {
            $path_parts = explode(":", $socket_path);
            $this->transport = $path_parts[0];
            $this->host = substr($path_parts[1], 2, strlen($path_parts[1]));
            if (count($path_parts) == 3) {
                $this->port = $path_parts[2];
            }
            JAXLLogger::info("trying " . $socket_path);
            if ($this->stream_context) {
                $this->fd = @stream_socket_client($socket_path, $this->errno, $this->errstr, $this->timeout, STREAM_CLIENT_CONNECT, $this->stream_context);
            } else {
                $this->fd = @stream_socket_client($socket_path, $this->errno, $this->errstr, $this->timeout);
            }
        } elseif (is_resource($socket_path)) {
            $this->fd =& $socket_path;
        } else {
            // Some error occurred.
        }
        if ($this->fd) {
            JAXLLogger::debug("connected to " . $socket_path . "");
            stream_set_blocking($this->fd, $this->blocking);
            // watch descriptor for read/write events
            JAXLLoop::watch($this->fd, array('read' => array(&$this, 'on_read_ready')));
            return true;
        } else {
            JAXLLogger::error(sprintf("unable to connect %s with error no: %s, error str: %s", is_null($socket_path) ? 'NULL' : $socket_path, is_null($this->errno) ? 'NULL' : $this->errno, is_null($this->errstr) ? 'NULL' : $this->errstr));
            $this->disconnect();
            return false;
        }
    }

Usage Example

예제 #1
0
파일: jaxl_sock5.php 프로젝트: jaxl/JAXL
 /**
  * @param string $ip
  * @param int $port
  * @return bool
  */
 public function connect($ip, $port = 1080)
 {
     $this->ip = $ip;
     $this->port = $port;
     $sock_path = $this->sock_path();
     if ($this->client->connect($sock_path)) {
         JAXLLogger::debug("established connection to {$sock_path}");
         return true;
     } else {
         JAXLLogger::error("unable to connect {$sock_path}");
         return false;
     }
 }
All Usage Examples Of JAXLSocketClient::connect