Implements low level logic for connecting, serving, reading to, and writing from WebSocket connections using PHP's streams. Unlike in previous versions of this library, a Socket instance now represents a single underlying socket resource. It's designed to be used by aggregation, rather than inheritance.
Inheritance: extends Wrench\Util\Configurable, implements Wrench\Resource
示例#1
0
 /**
  * URI Socket constructor
  *
  * @param string $uri     WebSocket URI, e.g. ws://example.org:8000/chat
  * @param array  $options (optional)
  *   Options:
  *     - protocol             => Wrench\Protocol object, latest protocol
  *                                 version used if not specified
  *     - timeout_socket       => int, seconds, default 5
  *     - server_ssl_cert_file => string, server SSL certificate
  *                                 file location. File should contain
  *                                 certificate and private key
  *     - server_ssl_passphrase => string, passphrase for the key
  *     - server_ssl_allow_self_signed => boolean, whether to allows self-
  *                                 signed certs
  */
 public function __construct($uri, array $options = array())
 {
     parent::__construct($options);
     list($this->scheme, $this->host, $this->port) = $this->protocol->validateSocketUri($uri);
 }
 /**
  * Constructor
  *
  * A server client socket is accepted from a listening socket, so there's
  * no need to call ->connect() or whatnot.
  *
  * @param resource $accepted_socket
  * @param array $options
  */
 public function __construct($accepted_socket, array $options = array())
 {
     parent::__construct($options);
     $this->socket = $accepted_socket;
     $this->connected = (bool) $accepted_socket;
 }
示例#3
0
 /**
  * @param Socket $socket
  * @return boolean
  */
 public function sendToSocket(Socket $socket)
 {
     $success = true;
     foreach ($this->frames as $frame) {
         $success = $success && $socket->send($frame->getFrameBuffer()) !== false;
     }
     return $success;
 }
示例#4
0
 /**
  * @dataProvider getValidNames
  * @param string $name
  */
 public function testGetNamePart($name, $ip, $port)
 {
     $this->assertEquals($ip, Socket::getNamePart($name, Socket::NAME_PART_IP), 'splits ip correctly');
     $this->assertEquals($port, Socket::getNamePart($name, Socket::NAME_PART_PORT), 'splits port correctly');
 }