Exemplo n.º 1
0
 /**
  * @param string $host
  * @param string $port
  * @param string $ticket
  */
 public function init($host, $port, $ticket)
 {
     $httpRequest = $this->buildRequest($ticket);
     $this->socket->create(AF_INET, SOCK_STREAM, SOL_TCP);
     $this->socket->connect(gethostbyname($host), $port);
     $this->socket->write($httpRequest, strlen($httpRequest));
     if (($status = $this->socket->read(self::FITNESSE_INTEGER)) != 0) {
         $errorMsg = $this->socket->read($status);
         $this->socket->close();
         throw new Exception("init() failed: " . $errorMsg . "\n");
     }
 }
Exemplo n.º 2
0
 public function create_listen($type, $protocol, $backlog = 0, $address = 0)
 {
     parent::create(AF_UNIX, $type, $protocol);
     $socket->bind($address);
     $socket->listen($backlog);
     return $socket;
 }
 public function testShutdown()
 {
     Socket::create()->setHost('localhost')->setPort(80)->close();
     $timedOutSocket = Socket::create()->setHost('google.com')->setPort(80)->setTimeout(1)->connect();
     $timedOutSocket->write("GET / HTTP/1.1\r\nHost: google.com\r\n\r\n");
     $timedOutSocket->read(256);
     $timedOutSocket->close();
     $this->assertEquals(42, 42);
 }
Exemplo n.º 4
0
 /**
  * socket遠程連接
  * @author wave
  */
 protected static function connect()
 {
     if (empty(self::$link)) {
         Socket::create();
         if (!socket_connect(self::$sock, self::$address, self::$port)) {
             exit(socket_strerror(socket_last_error()));
         }
         ++self::$link;
     }
 }
Exemplo n.º 5
0
 /**
  * Create an Instance of a Server rearing to go.
  *
  * @param string $address An IPv4, IPv6, or Unix socket address
  * @param int    $port
  * @param int    $timeout Seconds to wait on a socket before timing it out
  */
 public function __construct($address, $port = 0, $timeout = null)
 {
     set_time_limit(0);
     $this->address = $address;
     $this->port = $port;
     $this->timeout = $timeout;
     switch (true) {
         case filter_var($address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4):
             $this->domain = AF_INET;
             break;
         case filter_var($address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6):
             $this->domain = AF_INET6;
             break;
         default:
             $this->domain = AF_UNIX;
     }
     $this->masterSocket = Socket::create($this->domain, SOCK_STREAM, 0);
     $this->masterSocket->bind($this->address, $this->port);
     $this->masterSocket->getSockName($this->address, $this->port);
     $this->masterSocket->listen();
 }