View Single Post
Old 07-15-2009, 05:34 PM   #7 (permalink)
cad106uk
The Visitor
 
Join Date: Jul 2009
Posts: 3
Thanks: 0
cad106uk is on a distinguished road
Default fixed it

Aha,

Tony you where right about the socket_create stuff. After some reading up and re-writing and came up with this as a working php client :)

PHP Code:
<?php

error_reporting
(E_ALL);

echo 
"<h2>TCP/IP Connection</h2>\n";

/* Get the port for the WWW service. */
$service_port 1025;

/* Get the IP address for the target host. */
$address gethostbyname('localhost');

/* Create a TCP/IP socket. */
$socket socket_create(AF_INETSOCK_STREAMSOL_TCP);
if (
$socket === false) {
    echo 
"socket_create() failed: reason: " socket_strerror(socket_last_error()) . "\n";
} else {
    echo 
"OK. $socket\n";
}

echo 
"Attempting to connect to '$address' on port '$service_port'...";
$result socket_connect($socket$address$service_port);
if (
$result === false) {
    echo 
"socket_connect() failed.\nReason: ($result) " socket_strerror(socket_last_error($socket)) . "\n";
} else {
    echo 
"OK.\n";
}

$in "HEAD / HTTP/1.1\r\n";
$in .= "Host: www.example.com\r\n";
$in .= "Connection: Close\r\n\r\n";

echo 
"Sending HTTP HEAD request ... $in";
socket_write($socket$instrlen($in));
echo 
"OK.\n";

echo 
"Closing socket...";
socket_close($socket);
echo 
"OK.\n\n";

?>
cad106uk is offline  
Reply With Quote