/** * Open a new socket based on the instance information * * @param GameQ_Protocols $instance * @param bool $blocking * @throws GameQException * @return boolean|resource */ protected function socket_open(GameQ_Protocols $instance, $blocking = FALSE) { // Create the remote address $remote_addr = sprintf("%s://%s:%d", $instance->transport(), $instance->ip(), $instance->port()); // Create context $context = stream_context_create(array('socket' => array('bindto' => '0:0'))); // Create the socket if (($socket = @stream_socket_client($remote_addr, $errno = NULL, $errstr = NULL, $this->timeout, STREAM_CLIENT_CONNECT, $context)) !== FALSE) { // Set the read timeout on the streams stream_set_timeout($socket, $this->timeout); // Set blocking mode stream_set_blocking($socket, $blocking); } else { // Check to see if we are in debug mode, if so throw the exception if ($this->debug) { throw new GameQException(__METHOD__ . " Error creating socket to server {$remote_addr}. Error: " . $errstr, $errno); } // We didnt create so we need to return false. return FALSE; } unset($context, $remote_addr); // return the socket return $socket; }
/** * Overload so we can check for some special options * * @param string $ip * @param int $port * @param array $options */ public function __construct($ip = FALSE, $port = FALSE, $options = array()) { // Got to do this first parent::__construct($ip, $port, $options); // Check for override in master server port (query) if (isset($this->options['master_server_port']) && !empty($this->options['master_server_port'])) { // Override the master server port $this->master_server_port = (int) $this->options['master_server_port']; } }