sockets issues ?

From: Date: Thu, 26 Jul 2001 16:06:12 +0000
Subject: sockets issues ?
Groups: php.dev 
Request: Send a blank email to php-dev+get-61073@lists.php.net to get a copy of this message
Dear Developpers :) I have to developp a web page on which i need to connect to a game server, to send and grab some informations. The server used is coded in C++, with borland C++ Builder, and so it runs under Windows, and i don't have the source, but i know the protocol it uses, so i can communicate with it. Problem is that for several day i'm trying to use all the PHP Network functions, with success, for connecting, sending informations, closing the socket, but without any way to read like i want incoming informations on the socket. First i tried the way described in the PHP manual: while (!feof($fp)) { echo fgets ($fp,128); } result: the fgets seems to work (when i add a flush(); in the while it displays informations), but the while just make an infinite loop even if fgets return nothing. Then i tried to upgrade to PHP-4.0.6, because i saw some people complaining about the same problem with not updated PHP versions in the different mailing-lists, but no answers to them. result: problem still here. Then i tried the sockets functions, which seems very close of the unix socket functions, so i thought it may work. Recompiled PHP with --enable-sockets, recoded my .php to use those functions, and no, it didn't change anything, even with the different parameters usable ( PHP_BINARY_READ and PHP_NORMAL_READ and even non documented ones like PHP_SYSTEM_READ). I also tried non-documented functions (socket_create, socket_write, read, ...) but they do not seem to be enabled in non-CVS PHP versions. Then i tried that: $sock_tab = socket_get_status($sock); if ($sock_tab["unread_bytes"] >= 0) { $a_lire = true; while ($a_lire) { $bytes_left = $sock_tab["unread_bytes"]; print("<br>Reading from the socket: ($bytes_left bytes left in the socket buffer) <br>"); $buffer = fgets($sock, 128); print("$buffer"); flush(); $buffer=""; $sock_tab = socket_get_status($sock); if ($sock_tab["unread_bytes"] = 0) $a_lire = false; } print("$buffer<br>"); } else print("<br>No informations received on the socket.<br>"); result: still loop infinite, displays: Reading from the socket: (0 bytes left in the socket buffer) So i tried that: $sock_tab = socket_get_status($sock); while ($liste = each($sock_tab)) print("<br>Name: $liste[0] -> Value: $liste[1]<br>"); result: Name: timed_out -> Value: Name: blocked -> Value: 1 Name: eof -> Value: Name: unread_bytes -> Value: 0 comments: i *KNOW* the server is sending some informations so why all the read or socket_get_status are not working properly ... ? Thanks for your help, i really need it ... Arnauld Dravet smurfie@artefact21.net

« previous php.dev (#61073) next »