Esempio n. 1
0
 public function __construct($sServer, $iPort)
 {
     AirD::Log(AirD::LOGTYPE_INTERNAL, "socketClient's constructor", true);
     parent::__construct(Config::BIND_ADDRESS);
     $this->connect($sServer, $iPort);
     $this->set_non_block(true);
     SocketEngine::AddFd($this);
 }
Esempio n. 2
0
 public function __construct($socket)
 {
     AirD::Log(AirD::LOGTYPE_INTERNAL, "socketServerClient's constructor", true);
     $this->socket = $socket;
     if (!is_resource($this->socket)) {
         throw new socketException("Invalid socket or resource");
     } elseif (!socket_getsockname($this->socket, $this->local_addr, $this->local_port)) {
         throw new socketException("Could not retrieve local address & port: " . socket_strerror(socket_last_error($this->socket)));
     } elseif (!socket_getpeername($this->socket, $this->remote_address, $this->remote_port)) {
         throw new socketException("Could not retrieve remote address & port: " . socket_strerror(socket_last_error($this->socket)));
     }
     $this->on_connect();
     $this->set_non_block(true);
     SocketEngine::AddFd($this);
 }
Esempio n. 3
0
 public function __construct($bind_address = 0, $bind_port = 0, $domain = AF_INET, $type = SOCK_STREAM, $protocol = SOL_TCP)
 {
     $this->bind_address = $bind_address;
     $this->bind_port = $bind_port;
     $this->domain = $domain;
     $this->type = $type;
     $this->protocol = $protocol;
     if (($this->socket = @socket_create($domain, $type, $protocol)) === false) {
         throw new socketException("Could not create socket: " . socket_strerror(socket_last_error($this->socket)));
     }
     AirD::Log(AirD::LOGTYPE_INTERNAL, "SocketBase's constructor (FD " . (int) $this->socket . ")", true);
     if (!@socket_set_option($this->socket, SOL_SOCKET, SO_REUSEADDR, 1)) {
         throw new socketException("Could not set SO_REUSEADDR: " . $this->get_error());
     }
     if (!@socket_bind($this->socket, $bind_address, $bind_port)) {
         throw new socketException("Could not bind socket to [{$bind_address} - {$bind_port}]: " . socket_strerror(socket_last_error($this->socket)));
     }
     if (!@socket_getsockname($this->socket, $this->local_addr, $this->local_port)) {
         throw new socketException("Could not retrieve local address & port: " . socket_strerror(socket_last_error($this->socket)));
     }
     $this->set_non_block(true);
     SocketEngine::AddFd($this);
 }