flamerail Posted December 16, 2007 Share Posted December 16, 2007 I did a search and couldn't find any thing helpful so hopefully you guys can give me a hand, I'm trying to make a little scriptlet that will try to open a connection to my gmod server. It uses UDP://gmod.flamerail.com:27015. I wanted to have a little thing that would say rather my gmod server was up or down. Well I've just modded the code on php.net for the udp example and Im getting a resource ID problem with it. Heres the code <?php $fp = fsockopen("udp://gmod.flamerail.com", 27015, $errno, $errstr, 5); if (!$fp) { echo "ERROR: $errno - $errstr<br />\n"; } else { echo $fp; //Gives a resource ID } ?> Any help or ideas would be GREAT Link to comment https://forums.phpfreaks.com/topic/81870-fsockopen-with-udp-ports/ Share on other sites More sharing options...
flamerail Posted December 16, 2007 Author Share Posted December 16, 2007 Bump.... Link to comment https://forums.phpfreaks.com/topic/81870-fsockopen-with-udp-ports/#findComment-416230 Share on other sites More sharing options...
paul2463 Posted December 16, 2007 Share Posted December 16, 2007 if "echo" is echoing a Resource ID #13 etc, then it is doing exactly what it is being told to do PHP.net tells you this Return Values fsockopen() returns a file pointer which may be used together with the other file functions (such as fgets(), fgetss(), fwrite(), fclose(), and feof()). If the call fails, it will return FALSE what is the problem? Link to comment https://forums.phpfreaks.com/topic/81870-fsockopen-with-udp-ports/#findComment-416242 Share on other sites More sharing options...
flamerail Posted December 16, 2007 Author Share Posted December 16, 2007 How would I go about determining rather the connection was made or not. Thats basicly All i want to do. Thanks paul! Link to comment https://forums.phpfreaks.com/topic/81870-fsockopen-with-udp-ports/#findComment-416262 Share on other sites More sharing options...
paul2463 Posted December 16, 2007 Share Posted December 16, 2007 if you get a resource id number then the connection was made, if it was not made then fsockopen() returns false <?php $fp = fsockopen("udp://gmod.flamerail.com", 27015, $errno, $errstr, 5); if (!$fp) { echo "ERROR: $errno - $errstr } else { echo "Connection Made"; } ?> Link to comment https://forums.phpfreaks.com/topic/81870-fsockopen-with-udp-ports/#findComment-416267 Share on other sites More sharing options...
flamerail Posted December 16, 2007 Author Share Posted December 16, 2007 Well it sais connected even when the port is active an inactive.. Link to comment https://forums.phpfreaks.com/topic/81870-fsockopen-with-udp-ports/#findComment-416321 Share on other sites More sharing options...
corbin Posted December 16, 2007 Share Posted December 16, 2007 http://php.net/fsockopen Warning UDP sockets will sometimes appear to have opened without an error, even if the remote host is unreachable. The error will only become apparent when you read or write data to/from the socket. The reason for this is because UDP is a "connectionless" protocol, which means that the operating system does not try to establish a link for the socket until it actually needs to send or receive data. So this should work: if($fp = fsockopen('udp://gmod.flamerail.com', 27015, $errno, $errstr, 5) && fwrite($fp, "\n")) { echo 'Connected'; } else { echo 'Not connected'; } Random writes might cause errors with the udp server though.... I guess you could try to read from it instead (replace the fwrite with fread($fp, 1)). Link to comment https://forums.phpfreaks.com/topic/81870-fsockopen-with-udp-ports/#findComment-416326 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.