472,780 Members | 1,602 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,780 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 5726
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: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.