Hi!
I'm trying to speed up a big application by splitting it into a codebase
acting as a server and the actual scripts communicating with the server
using sockets.
I got the server working, at least it works when I send a request via
telnet. When I try to let a script act as the client I get no response. I
think the problem is the length parameter in the read()-function.
Not all requests and results are 2048 bytes, but I have no idea what to use
as a delimiter instead.
Here are the scripts so far:
Server:
// Socket was created, bind & listen executed
do {
if (($msgsock = accept_connect($sock)) < 0) { // wait for request
echo "accept_connect() failed: reason: " . strerror ($msgsock) .
"\n";
break;
}
do {
$buf = '';
$ret = read ($msgsock, $buf, 2048); // read request
echo "request: $ret <br>";
if ($ret < 0) {
echo "read() failed: reason: " . strerror ($ret) . "\n";
break 2;
}
if ($ret == 0) {
break 2;
}
$buf = trim ($buf);
$talkback = eval($buf); //
request verabeiten
write ($msgsock, $talkback, strlen ($talkback)); // write result to
socket
echo "$buf\n";
} while (true);
close ($msgsock);
} while (true);
Client:
// Socket was created; submitting request
write ($socket, $in, strlen ($in));
while (read ($socket, $out, 2048)) // reading response. what if
the response is < 2048 bytes?
{
echo $out;
}
As I said: The server works perfectly using telnet, but the script-client
does not give any output, allthough the connection was created successfully.
Thanks in advance for any answers. I hope I was able to describe the problem
well enough.
Matt
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]