connect() public method

public connect ( string | resource $socket_path )
$socket_path string | resource
Esempio n. 1
0
 /**
  * @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;
     }
 }
Esempio n. 2
0
 /**
  * @param string $name
  * @param callable $read_cb TODO: Currently not used
  */
 public function __construct($name, $read_cb = null)
 {
     // TODO: see JAXL->cfg['priv_dir']
     $this->pipes_folder = getcwd() . '/.jaxl/pipes';
     if (!is_dir($this->pipes_folder)) {
         mkdir($this->pipes_folder, 0777, true);
     }
     $this->ev = new JAXLEvent();
     $this->name = $name;
     // TODO: If someone's need the read callback and extends the JAXLPipe
     // to obtain it, one can't because this property is private.
     $this->read_cb = $read_cb;
     $pipe_path = $this->get_pipe_file_path();
     if (!file_exists($pipe_path)) {
         posix_mkfifo($pipe_path, $this->perm);
         $this->fd = fopen($pipe_path, 'r+');
         if (!$this->fd) {
             JAXLLogger::error("unable to open pipe");
         } else {
             JAXLLogger::debug("pipe opened using path {$pipe_path}");
             JAXLLogger::notice("Usage: \$ echo 'Hello World!' > {$pipe_path}");
             $this->client = new JAXLSocketClient();
             $this->client->connect($this->fd);
             $this->client->set_callback(array(&$this, 'on_data'));
         }
     } else {
         JAXLLogger::error("pipe with name {$name} already exists");
     }
 }
Esempio n. 3
0
 public function test_jaxl_socket_client()
 {
     $sock = new JAXLSocketClient();
     $sock->connect('tcp://127.0.0.1:5222');
     $sock->send("<stream:stream>");
     while ($sock->fd) {
         $sock->recv();
     }
 }
 function test_jaxl_socket_client()
 {
     $sock = new JAXLSocketClient("127.0.0.1", 5222);
     $sock->connect();
     $sock->send("<stream:stream>");
     while ($sock->fd) {
         $sock->recv();
     }
 }