From:             psychi at freakmail dot de
Operating system: Linux 2.6.14.5
PHP version:      5.1.2
PHP Bug Type:     Sockets related
Bug description:  Available data isn't fread()

Description:
------------
Hello.

I tried to write a small icq client and connected to the icq server,
received the hello packet (10 bytes, as you can see in the example) and
sent a packet to the icq server (23 bytes) back. The problem is that the
next call of socket_read() returns "unable to read from socket [104]:
Connection reset by peer". This message generally is ok, because icq
closes the connection - but there should be still waiting data for me (see
Commview Log).

Where did "Paket #3" go? I can't read it with PHP, but i don't know why -
but it should by somewhere... in my opinion. Tried this also with PHP
5.0.5 with same result... hope this is enough information.

- Thanks -

Commview Log (produced by given code)

Paket #1
0x0000   2A 01 B5 D2 00 04 00 00-00 01                     *.µÒ......

Paket #2
0x0000   2A 01 00 02 00 11 00 00-00 01 00 01 00 09 01 01  
*...............
0x0010   01 01 01 01 01 01 01                              .......

Paket #3
0x0000   2A 04 B5 D3 00 3A 00 01-00 09 01 01 01 01 01 01  
*.µÓ.:..........
0x0010   01 01 01 00 04 00 23 68-74 74 70 3A 2F 2F 77 77  
......#http://ww
0x0020   77 2E 61 6F 6C 2E 63 6F-6D 3F 63 63 6F 64 65 3D  
w.aol.com?ccode=
0x0030   75 73 26 6C 61 6E 67 3D-65 6E 00 08 00 02 00 04  
us&lang=en......

Reproduce code:
---------------
<?PHP

  socket_clear_error();
  $connection=socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
  socket_connect($connection, gethostbyname("login.icq.com"), 5190);
  $socket_data=socket_read($connection, 10, PHP_BINARY_READ);
  echo "-> ".strlen($socket_data)."<br>"; flush();
  socket_write($connection,
"\x2A\x01\x00\x02\x00\x11\x00\x00\x00\x01\x00\x01\x00\x09\x01\x01\x01\x01\x01\x01\x01\x01\x01");
  $socket_data=socket_read($connection, 1, PHP_BINARY_READ);
  echo "-> ".strlen($socket_data)."<br>"; flush();

?>

Expected result:
----------------
-> 10

-> 1

Actual result:
--------------
-> 10

Warning: socket_read() [function.socket-read]: unable to read from socket
[104]: Connection reset by peer in /home/html/icq.php5 on line 11
-> 0

-- 
Edit bug report at http://bugs.php.net/?id=36354&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=36354&r=trysnapshot44
Try a CVS snapshot (PHP 5.1): 
http://bugs.php.net/fix.php?id=36354&r=trysnapshot51
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=36354&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=36354&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=36354&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=36354&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=36354&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=36354&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=36354&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=36354&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=36354&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=36354&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=36354&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=36354&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=36354&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=36354&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=36354&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=36354&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=36354&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=36354&r=mysqlcfg

Reply via email to