I found this in PHP manual, but it doesn't work in my pc.
It tells me this:
Fatal error: Call to undefined function: socket() in c:\inetpub\sup\sclient.php on line 9
Dunno why of this error. I've latest PHP installed: 4.1.2 working fine !!
I've installed it as an APACHE module in my Windows NT 4 Server...
Any suggestions? Thanks
PS: I suppose the connect function don't exist too because i've not found any info
in www.php.net function reference...
PS: If you wonder, i'm trying to connect from PHP to a Server made in Delphi by TCP/IP or something like that. I tried with fsockopen but it doesn't work fine... should write another thread 4 this...
<?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.php.net');
/ Create a TCP/IP socket. /
$socket = socket(AF_INET, SOCK_STREAM, 0);
if ($socket < 0) {
echo "socket() failed: reason: " . strerror($socket) . "\n";
} else {
"socket() successful: " . strerror($socket) . "\n";
}
echo "Attempting to connect to '$address' on port '$service_port'...";
$result = connect($socket, $address, $service_port);
if ($result < 0) {
echo "connect() failed.\nReason: ($result) " . strerror($result) . "\n";
} else {
echo "OK.\n";
}
$in = "HEAD / HTTP/1.0\r\n\r\n";
$out = '';
echo "Sending HTTP HEAD request...";
write($socket, $in, strlen($in));
echo "OK.\n";
echo "Reading response:\n\n";
while (read($socket, $out, 2048)) {
echo $out;
}
echo "Closing socket...";
close($socket);
echo "OK.\n\n";
?>