473,387 Members | 1,611 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 5794
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Michael T. Peterson | last post by:
I am trying to get the file referenced by the following url: http://waterdata.usgs.gov/wa/nwis/uv?dd_cd=01&dd_cd=02&format=rdb&period=1&site_no=12149000 I'm using parse_url to get the host,...
2
by: Colin Bell | last post by:
I'm stuck on a problem with getting data from a XML data stream. This stream is large and trying to use fsockopen to get the stream down. I've tetsed the code by telneting into the machine/port...
1
by: chaos | last post by:
Hello, i have problems using sqlj in the following environment. I use type 4 driver com.ibm.db2.jcc.DB2Driver and connect succesful to 8.1. db2-Database(DRDA)(Informational tokens are "DB2...
2
by: Paul Duncan | last post by:
diggityduncs (Programmer) Nov 13, 2003 Hello, I'm tring to use a win32/api dll in c# The vendor I received the dll from doesn't know anything about .net I received two files ACGAPI.DLL +
1
by: Skeets | last post by:
i'm having some php problems. i have the following code on my main page: ------------ $fp = fsockopen("127.0.0.1", 49152, $errno, $errrstr, 30); if (!$fp) { echo "socket error: $errstr...
3
by: Aetherweb | last post by:
Hi, I need to use fsockopen to open a connection, send a GET request and read in the response. At the moment I'm trying the following code, but I think it's ignoring the actual URL included in...
24
by: allpervasive | last post by:
hi all, this is reddy, a beginner to c lang,,here i have some problems in reading and modifying the contents of a file,, hope you can help to solve this problem. Here i attach the file to be...
3
by: Brett R. Wesoloski | last post by:
I am having problems using HttpContext.Current.Request.Url.Host. I have some code that does this... if (HttpContext.Current != null) { subdomain = HttpContext.Current.Request.Url.Host; }
2
by: haytham2008 | last post by:
hi every body i have this problem while i trying to send email using php i found a function <?php mail(); ?> but does not work with me since i use smtp server with user name and password
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.