|
Posted by Martn Marqus on 10/05/29 11:15
OK, I found the error. Aparently, the message that I was sending didn't have a
newline at the end, and so socket_read on the other end failed to complete
it's task, and finds it self with a conection reset by pear when the client
tries to write something else.
I found out when looking at the Net_Socket Object in PEAR, and say that the
was a write() and a writeLine() method in the class, an after trying it out,
it worked!
Sorry for the noise. :-)
El Vie 06 May 2005 16:48, Martín Marqués escribió:
> El Vie 06 May 2005 01:50, Richard Lynch escribió:
>
> The client code is this:
>
> <?php
> ini_set ("display_errors" , "On" );
> if (($socket = socket_create (AF_INET, SOCK_STREAM, SOL_TCP)) < 0) {
> echo "socket_create() failed: reason: " . socket_strerror ($socket) .
> "\n";
> }
>
> $result = socket_connect($socket, '127.0.0.1', 9100);
> var_dump($result);
> $msg = "prueba de socket";
>
> $res = socket_write($socket, $msg, strlen($msg));
> var_dump(socket_strerror(socket_last_error($socket)));
> exit;
> ?>
>
> The daemon code is like this:
>
> #!/usr/bin/php
> <?php
> ini_set ("display_errors" , "On" );
>
> error_reporting(E_ALL);
>
> /* Allow the script to hang around waiting for connections. */
> set_time_limit(0);
>
> /* Turn on implicit output flushing so we see what we're getting
> * as it comes in. */
> ob_implicit_flush();
>
> $address = '127.0.0.1';
> $port = 9100;
>
> if (($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) < 0) {
> echo "socket_create() failed: reason: " . socket_strerror($sock) . "\n";
> }
>
> if (($ret = socket_bind($sock, $address, $port)) < 0) {
> echo "socket_bind() failed: reason: " . socket_strerror($ret) . "\n";
> }
>
> if (($ret = socket_listen($sock, 5)) < 0) {
> echo "socket_listen() failed: reason: " . socket_strerror($ret) . "\n";
> }
>
> do {
> if (($msgsock = socket_accept($sock)) < 0) {
> echo "socket_accept() failed: reason: " . socket_strerror($msgsock) .
> "\n";
> break;
> }
> var_dump($msgsock);
> do {
> if (false === ($buf = socket_read($msgsock, 2048, PHP_NORMAL_READ))) {
> echo "socket_read() failed: reason: " . socket_strerror($ret) . "\n";
> break 1;
> }
> if (!$buf = trim($buf)) {
> continue;
> }
> if ($buf == 'quit') {
> break;
> }
> if ($buf == 'shutdown') {
> socket_close($msgsock);
> break 2;
> }
> } while (true);
> socket_close($msgsock);
> } while (true);
>
> socket_close($sock);
> ?>
>
> But when I try to connect with the PHP client (even executing it with CLI
> interface) I get this message in the daemons output:
>
>
> Warning: socket_read() unable to read from socket [54]: Connection reset by
> peer in /root/printSocket.php on line 36
> socket_read() failed: reason: Operation not permitted
>
>
> --
> 16:32:53 up 35 days, 1:01, 2 users, load average: 0.70, 0.52, 0.59
> -----------------------------------------------------------------
> Martín Marqués | select 'mmarques' || '@' || 'unl.edu.ar'
> Centro de Telematica | DBA, Programador, Administrador
> Universidad Nacional
> del Litoral
> -----------------------------------------------------------------
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
18:11:30 up 35 days, 2:40, 2 users, load average: 0.74, 0.72, 0.71
-----------------------------------------------------------------
Martín Marqués | select 'mmarques' || '@' || 'unl.edu.ar'
Centro de Telematica | DBA, Programador, Administrador
Universidad Nacional
del Litoral
-----------------------------------------------------------------
[Back to original message]
|