Server program won't write back to client
| From: | Bob | Date: | Mon, 11 Sep 2000 18:02:26 +0000 |
| Subject: | Server program won't write back to client | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-16200@lists.php.net to get a copy of this message | ||
----- Original Message -----
From: Bob
To: php-general@lists.php.net
Sent: Monday, September 11, 2000 7:01 AM
Subject: Server program won't write back to client
Server accepts information from client but won't write back to client. The client just hangs
until it times out.
If anyone can tell me a workaround for this problem, I would really appreciate it or if anyone has a
simple client/server program in php, that would also do.
Server Code
//connection info....
do {
if(($msgsock = accept_connect($sock)) < 0) {
print("accept_connect() failed: reason:" . strerror($msgsock) . "\n");
break;
}
do {
$buf = '';
$ret = read($msgsock, $buf,10000);
if($ret < 0) {
print("read() failed: reason:" . strerror($ret) . "\n");
break 2;
}
if($ret == 0) {
break 2;
}
$buf = trim($buf);
if($buf == 'quit') {
close($msgsock);
break ;
}
$talkback = "PHP: You said '$buf'.\r\n";
write($msgsock, $talkback, strlen($talkback));
print("$buf<br>\n");
print("Talkback: $talkback<br>\n That's all folks.");
}
while(true);
close($msgsock);
}
while(true);
close($sock);
Client Code Complete code
function whois_request($server, $query) {
$data = "";
$fp=fsockopen($server, 23007);
print("Connection: $fp");
if ($fp) {
fputs($fp, $query. "\r\n");
while(!feof($fp)) {
$data .= fread($fp, 1000);
}
fclose($fp);
}
return $data;
}
?>
<FORM>
<INPUT TYPE=HIDDEN NAME=action VALUE=query>
<INPUT TYPE=TEXT NAME=query VALUE="<?echo $query?>">
<INPUT TYPE=SUBMIT VALUE= " OK ">
</FORM>
<?
$server = "24.113.2.99";
if($action == "query") {
$data = whois_request($server, $query);
echo("Send $query to $server.<p>");
echo("Output: <p> <pre>$data</pre><p>");
echo(" Socks: $fp");
}
?>