Re: Socket connection reset by pear

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux