Esempio n. 1
0
 /**
  * TODO: Proper header generation!
  * TODO: Check server response!
  */
 public function open()
 {
     $errno = $errstr = null;
     $protocol = $this->scheme == 'ws' ? "tcp" : "ssl";
     $this->socket = stream_socket_client("{$protocol}://{$this->host}:{$this->port}", $errno, $errstr, $this->getTimeOut());
     // socket_connect($this->socket, $this->host, $this->port);
     $buffer = $this->serializeHeaders();
     fwrite($this->socket, $buffer, strlen($buffer));
     // wait for response
     $buffer = WebSocketFunctions::readWholeBuffer($this->socket);
     $headers = WebSocketFunctions::parseHeaders($buffer);
     $s = new WebSocketSocket($this, $this->socket, $immediateWrite = true);
     if ($this->hybi) {
         $this->_connection = new WebSocketConnectionHybi($s, $headers);
     } else {
         $this->_connection = new WebSocketConnectionHixie($s, $headers, $buffer);
     }
     $s->setConnection($this->_connection);
     return true;
 }