예제 #1
0
 public function testSendAndReceive()
 {
     $requestString = "HEAD / HTTP/1.0\r\n\r\n";
     $connection = new Connection($this->host);
     $connection->connect();
     $connection->sendRequest($requestString);
     $responseString = $connection->receiveResponse();
     $this->assertNotNull($responseString);
     $responseLines = explode("\r\n", $responseString);
     $responseStatus = array_shift($responseLines);
     $this->assertEquals('HTTP/1.1 200 OK', $responseStatus);
 }
예제 #2
0
 /**
  * Gets the connection with the server of the provided URL
  * @param zibo\library\Url $url The URL to get a connection for
  * @return zibo\library\network\Connection A network connection with the server of the provided URL
  */
 protected function getConnection(Url $url)
 {
     $id = $this->getConnectionId($url);
     if (array_key_exists($id, $this->connections)) {
         $connection = $this->connections[$id];
     } else {
         $host = $url->getHost();
         $port = $url->getPort();
         $isSecured = $url->getProtocol() == Url::PROTOCOL_HTTPS ? true : false;
         $connection = new Connection($host, $port, $isSecured);
         $this->connections[$id] = $connection;
     }
     $connection->connect();
     return $connection;
 }