Re: UDP????

From: Date: Sun, 20 Aug 2000 20:51:26 +0000
Subject: Re: UDP????
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-12670@lists.php.net to get a copy of this message
John Hermsen writes: > I want to make a udp connection, but some how I can't get it to work. > > I have tried the following example from the php site, but I just get a blank > page. > > <?php > $fp = fsockopen("udp://127.0.0.1",13, &$errno, &$errstr); > if (!fp) { > echo "ERROR: $errno - $errstr<br>\n"; > } else { > fwrite($fp,"\n"); > echo fread($fp, 26); > fclose($fp); > } > ?> > > What am I doing wrong and do I have to compile PHP with some option to > enable these options? > > Regards, > John UDP support has only been available since PHP 4 beta 4, released on Feb 20 2000. So if you have a more recent version than that, it should be available without a recompile. However, the example in the manual had one syntax error in particular which would cause the error condition never to execute, even if there had been an error: 'if (!fp)' should be written 'if (!$fp)'. This has been fixed and the proper syntax is now on http://www.php.net/manual/function.fsockopen.php. However, even once you've fixed that, you'd need to have the daytime service running on the server to which you are attempting to connect. For instance, on my server, I had to edit /etc/inetd.conf to uncomment port 13's daytime service, then 'killall -HUP inetd'. After this, the example works fine. Hope this helps, Torben -- +----------------------------------------------------------------+ |Torben Wilson <torben@php.net> Netmill iTech| |http://www.coastnet.com/~torben http://www.netmill.fi| |Ph: 1 250 383-9735 torben@netmill.fi| +----------------------------------------------------------------+

« previous php.general (#12670) next »