php fread'ing problem
Moderator: General Moderators
-
TooCrooked
- Forum Newbie
- Posts: 7
- Joined: Fri Oct 27, 2006 6:17 am
php fread'ing problem
many thanks!
Last edited by TooCrooked on Thu Jun 07, 2007 3:40 pm, edited 1 time in total.
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
I've never done anything involving sockets before so I'm not really much use to you but considering your post and its over-specification I urge you, if you wish to benefit from others helping you, to explain in simple terms what you are trying to do and how you are going about doing it. You should also show the simplest possible code recreation of the problem you are experiencing. Both of these are necessary for others to see and understand the problem and thus find a solution.
Now the server isn't sending any data or something else goes wrong, what does this function do? fread() returns false or "nothing", and Ord(false) returns 0, GetByte() returns 0. Nothing in the script notices that no data was read but a timeout occured.TooCrooked wrote:function GetByte() {return Ord(fread($this->sp, 1));}
scenario: you ping a server that needs some time to handle the request. $this->GetInt32(); is your first read operation. It calles GetByte() four times. The first GetByte() has a timeout -> return 0, GetInt32() is happy, it gets a byte. Now the server is ready to send the data. GetByte() #2 reads the first byte of the actual data. From here on everything is shifted one byte.
If you use php5 you can test the return value of fread() and then throw an exception. Do you use php5?