Re: Yet another socket question...
| From: | René Fournier | Date: | Thu, 31 Jul 2003 21:43:03 +0000 |
| Subject: | Re: Yet another socket question... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-157832@lists.php.net to get a copy of this message | ||
On Thursday, July 31, 2003, at 02:45 PM, Chris Shiflett wrote:
--- René_Fournier <rene@smartslitters.com> wrote:I know, but I'm not talking about writing to the socket, just echoing to the local Server command line. I would expect the echo'd text to appear in the server terminal window as the script runs--but it only appears when the server terminates. Here's the code: <? set_time_limit (0); $host = "192.168.0.77"; $port = 1234; $socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n"); $result = socket_bind($socket, $host, $port) or die("Could not bind to socket\n"); $result = socket_listen($socket, 3) or die("Could not set up socket listener\n"); echo "Waiting for connections...\n"; $spawn = socket_accept($socket) or die("Could not accept incoming connection\n"); echo "Received connection request\n"; $welcome = "Welcome!\n> "; socket_write($spawn, $welcome, strlen ($welcome)) or die("Could not send connect string\n"); $input = socket_read($spawn, 1024) or die("Could not read input\n"); socket_write($spawn, strrev($input), strlen ($input)) or die("Could not send\n"); socket_close($spawn); socket_close($socket); echo "Socket terminated\n"; ?> (Now I start the server:) [Valhalla:~] rene% /usr/local/php/bin/php socket5.php4 (In another terminal window:) [Valhalla:~] rene% telnet 192.168.0.77 1234 Trying 192.168.0.77... Connected to 192.168.0.77. Escape character is '^]'. Welcome!Is it normal for a socket server to output all the echo'd messages only after the socket terminates?Can you explain what situation you're trying to describe? For example, echo does not write to a socket, so there's more going on than you're telling us.
(Now, even though the server is running and a socket is connected, the server window does not echo "Waiting for connections...".) In the client window, I type:
Hello worlddlrow olleHConnection closed by foreign host. [Valhalla:~] rene% (Now something happens in the server window:) [Valhalla:~] rene% /usr/local/php/bin/php socket5.php4 Waiting for connections... Received connection request Socket terminated [Valhalla:~] rene% (But when you look at the source code, shouldn't the "Waiting for connections" display as soon as the server is running, or at least when I try to telnet to it? Why would it wait until terminated??)