?php error_reporting (E_ALL); echo "h2 TCP / IP Connection / h2 \n"; / * Get the port for the WWW service. * / $service_port = getservbyname ('www', 'tcp'); / * Get the IP address for the target host. * / $address = gethostbyname ('www.example.com'); / * Create a TCP / IP socket. * / $socket = socket_create (AF_INET, SOCK_STREAM, 0); if ($socket 0) {echo "socket_create() failed: reason:". socket_strerror ($socket). "\n";} else {echo "OK.\n";} echo "Attempting to connect to '$address' on port '$service_port'.. ."; $result = socket_connect ($socket, $address, $service_port); if ($result 0) {echo "socket_connect() failed.\nReason: ($result) ". socket_strerror($result). "\n";} else {echo "OK.\n";} $in = "HEAD / HTTP / 1.0\r\n\r\n"; $out = ''; echo "Sending HTTP HEAD request.. ."; socket_write ($socket, $in, strlen ($in)); echo "OK.\n"; echo "Reading response:\n\n"; while ($out = socket_read ($socket, 2048)) {echo $out;} echo "Closing socket.. ."; socket_close ($socket); echo "OK.\n\n";?
?php error_reporting (E_ALL); echo "h2 Connexion TCP / IP / h2 \n"; / * Lit le port du service WWW. * / $service_port = getservbyname ('www', 'tcp'); / * Lit l'adresse IP du serveur de destination * / $address = gethostbyname ('www.exemple.com'); / * Cree une socket TCP / IP. * / $socket = socket_create (AF_INET, SOCK_STREAM, 0); if ($socket 0) {echo "socket_create() a eacute;chou eacute;: raison:". socket_strerror ($socket). "\n";} else {echo "OK.\n";} echo "Essai de connexion agrave; '$address 'sur le port '$service_port'.. ."; $result = socket_connect ($socket, $address, $service_port); if ($result 0) {echo "socket_connect() a eacute;chou eacute;: raison: ($result) ". socket_strerror($result). "\n";} else {echo "OK.\n";} $in = "HEAD / HTTP / 1.0\r\n\r\n"; $out = ''; echo "Envoi de la requ ecirc;te HTTP HEAD.. ."; socket_write ($socket, $in, strlen ($in)); echo "OK.\n"; echo "Lire la r eacute;ponse: \n\n"; while ($out = socket_read ($socket, 2048)) {echo $out;} echo "Fermeture de la socket.. ."; socket_close ($socket); echo "OK.\n\n";?