There is two client socket programe !
the first i can get the return , but the second i cant .
why ?
The first :
<?php
$url = '192.168.0.1';
$port = 5000;
$fp = fsockopen($url, $port);
if (!fp)
echo "error\n";
$request="01 booklist select * from contentlist";
$headlen = strlen($request);
//$len = fwrite($fp, $headlen, 2);
//echo $len;
echo "\n";
$len = fwrite($fp, $request, $headlen);
echo $len;
echo "\n";
while (!feof ($fp)){
$tmp_a = fread($fp, 128); //get result
echo $tmp_a;
}
fclose($fp);
?>
The second :
<?php
error_reporting(E_ALL);
/ Get the port for the WWW service. /
$service_port = 5000;
/ Get the IP address for the target host. /
$address = '192.168.0.1';
/ Create a TCP/IP socket. /
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket < 0) {
echo "socket_create() failed: reason: " . socket_strerror($socket) . "\n";
} else {
echo "\n";
}
$result = socket_connect($socket, $address, $service_port);
if ($result < 0) {
echo "socket_connect() failed.\nReason: ($result) " . socket_strerror($result) . "\n";
} else {
echo "\n";
}
$in = "01 booklist select * from contentlist";
//$out = '';
socket_write($socket, $in, strlen($in));
while ($out = socket_read($socket, 0, PHP_BINARY_READ)) {
echo $out;
}
socket_close($socket);
?>