470,833 Members | 1,350 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,833 developers. It's quick & easy.

Problems using fsockopen, stream_set_timeout and fgets


I'm communicating with a server using UDP, and it can be
narrowed down to this:

$us = 75000; //Timeout in microseconds.
$con = fsockopen("udp://127.0.0.0","23000");
stream_set_timeout($con,0,$us);
fwrite($con"\xff\info\");
$retval = fgets($con,10240);

My problem is that I allways have to wait for $us seconds.
So if I set it to 2 seconds, I have to wait for 2 seconds.
And if I set it to low, I might not wait long enough to get
an answer. So I've ended up using 0.075 seconds, which isn't
all that much. But I'd much rather find another way of
doing this, so that I can set the timeout as high as I like,
and still not have to wait longer than it takes to actually
retrieve the data.

Would reading one byte at a time, and check the last recieved
bytes for a known pattern resolve this...? Any suggestions?

-Fred

P.S. I haven't been able to play around and try different things
with this yet, due to deadlines on a couple of other projects...

--
Fred H

void FredH::Contact() {
TextToSpeach.say("frode at age dee dee dot en oh");
}
Jul 17 '05 #1
2 5552
On Mon, 23 Feb 2004 14:58:01 +0000, Fred H wrote:
I'm communicating with a server using UDP, and it can be narrowed down to
this:

$us = 75000; //Timeout in microseconds. $con =
fsockopen("udp://127.0.0.0","23000"); stream_set_timeout($con,0,$us);
fwrite($con"\xff\info\");
$retval = fgets($con,10240);


I don't see any reason to use stream_set_timeout() with UDP since UDP is
connectionless. Sometimes, fsockopen() won't even tell you that something
went wrong; you'll find this out reading/writing to the resource.

I say try working with it without the timeout. Look for errors using
fwrite()/fgets() and then take the appropriate decisions.

--
Daniel
Jul 17 '05 #2
> I don't see any reason to use stream_set_timeout() with UDP since UDP is
connectionless. Sometimes, fsockopen() won't even tell you that something
went wrong; you'll find this out reading/writing to the resource.
But if I read, and there is nothing to read, won't I just hang if I haven't
set a timeout...?
I say try working with it without the timeout. Look for errors using
fwrite()/fgets() and then take the appropriate decisions.


Doesn't work. It just hangs...

--
Fred H

void FredH::Contact() {
TextToSpeach.say("frode at age dee dee dot en oh");
}
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Michael T. Peterson | last post: by
2 posts views Thread by Colin Bell | last post: by
2 posts views Thread by Paul Duncan | last post: by
1 post views Thread by Skeets | last post: by
3 posts views Thread by Brett R. Wesoloski | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.