PHP Classes

File: doc/example/socket_test.php

Recommend this page to a friend!
  Classes of Gustavo Gomes   Client and Server Socket   doc/example/socket_test.php   Download  
File: doc/example/socket_test.php
Role: Example script
Content type: text/plain
Description: client socket and url example
Class: Client and Server Socket
Implement TCP/IP client and servers
Author: By
Last change:
Date: 17 years ago
Size: 872 bytes
 

Contents

Class file image Download
<?php
require_once("../../Socket.php");
require_once(
"../../URL.php");

error_reporting(E_ALL);
try {
   
/* Test of the Socket creation - connect with HTTP server and read
     * contents.
    $socket = new Socket();
    $socket->connect("www2.fsb.com.br",80);
    if ($socket->isConnected())
        echo "Connected...";
    $socket->write("GET / HTTP/1.1\r\n",20);
    echo $socket->read(20);
    */
   
   
    /* Test of the URL getting content
     */
   
$url = new URL("www.google.com.br/");
   
//** Url simple tests
    //echo $url->getExternalForm();
    //echo $url->getContent();
    //**
   
$conn = $url->openConnection();
   
$conn->connect();
   
print_r($conn->getRequestProperties());
    echo
$conn->getContentLength()." - ".$conn->getContentEncoding();
    echo
$conn->getContent();
   
/**/
} catch (SocketException $se) {
    echo
$se;
} catch (
UnknownHostException $uhe) {
    echo
$uhe;
} catch (
Exception $e) {
    echo
$e;
}
?>