Re: [PHP] Socket connection reset by pear
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 - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Socket connection reset by pear
On Thu, May 5, 2005 5:20 am, Martín Marqués said: I'm trying to build some communication aside of the server thin client stuff, with a socket daemon and a socket client. The daemon is the same that everybody can find in the PHP docs (example 1). The client simply opens a connection to the daemon and writes data using the socket Object from PEAR (last stable version). The problem is that it fails to make a socket_read() with this message (on the daemon side): Warning: socket_read() unable to read from socket [54]: Connection reset by peer in /space/home/martin/programacion/siprebi-1.2/ext/impresion/printSocket.php on line 42 socket_read() failed: reason: Operation not permitted If I open a telnet conection to the daemon, everything works like a charme. It writes and quits OK. What can be going wrong? Operation not permitted would make me guess you've got a user read/write permissions problem. When you open that telnet connection, are you logged in as the same user as the PHP user that is running the client script? I'm guessing not... You have to clarify, for yourself, which user is doing what when to which files/devices/sockets, and what chown permissions are in effect. That generally makes you go Duh and fix the problem pretty quick. -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Socket connection reset by pear
El Vie 06 May 2005 01:50, Richard Lynch escribió: On Thu, May 5, 2005 5:20 am, Martín Marqués said: I'm trying to build some communication aside of the server thin client stuff, with a socket daemon and a socket client. The daemon is the same that everybody can find in the PHP docs (example 1). The client simply opens a connection to the daemon and writes data using the socket Object from PEAR (last stable version). The problem is that it fails to make a socket_read() with this message (on the daemon side): Warning: socket_read() unable to read from socket [54]: Connection reset by peer in /space/home/martin/programacion/siprebi-1.2/ext/impresion/printSocket.php on line 42 socket_read() failed: reason: Operation not permitted If I open a telnet conection to the daemon, everything works like a charme. It writes and quits OK. What can be going wrong? Operation not permitted would make me guess you've got a user read/write permissions problem. Permissions where? On the file that is been executed? Everything looks OK. When you open that telnet connection, are you logged in as the same user as the PHP user that is running the client script? I'm guessing not... You have to clarify, for yourself, which user is doing what when to which files/devices/sockets, and what chown permissions are in effect. That generally makes you go Duh and fix the problem pretty quick. Well not really. I just tried running both scripts (daemon and client) from the same machine, both as root, and I still get a connection reset by pear. 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
[PHP] Socket connection reset by pear
I'm trying to build some communication aside of the server thin client stuff, with a socket daemon and a socket client. The daemon is the same that everybody can find in the PHP docs (example 1). The client simply opens a connection to the daemon and writes data using the socket Object from PEAR (last stable version). The problem is that it fails to make a socket_read() with this message (on the daemon side): Warning: socket_read() unable to read from socket [54]: Connection reset by peer in /space/home/martin/programacion/siprebi-1.2/ext/impresion/printSocket.php on line 42 socket_read() failed: reason: Operation not permitted If I open a telnet conection to the daemon, everything works like a charme. It writes and quits OK. What can be going wrong? -- 09:11:45 up 33 days, 17:40, 1 user, load average: 0.64, 0.79, 0.68 - 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