marked Posted November 5, 2006 Share Posted November 5, 2006 Hi all,This is driving me spare.Using the following code:[code]function openServerConnection($ip,$port){ global $serverResponse; $socket = fsockopen("udp://".$ip,$port,$errno,$errstat,30); if ($socket === false) echo "Connection fault: $errno - $errstr<br>\n"; else { socket_set_timeout($socket, 3); $startTime = getTime(); fwrite($socket, "\xFF\xFF\xFF\xFFgetstatus\x00"); $serverString = fread($socket, 2048); $endTime = getTime(); } fclose($socket); $serverResponse = (int)(($endTime - $startTime) * 1000); if($serverString) { sortData($serverString); return true; } else return false; }[/code]I have a LAMP setup at home, and on my localhost test server this code works fine. However uploading to my web host, it doesn't work at all. The error seems to be in the fwrite or fread lines, because the serverString variable never contains a value, while endTime and startTime are populated correctly.Is it likely that my host doesn't allow fread/fwrite or something? Anyone else had similar?Thanksmark Quote Link to comment Share on other sites More sharing options...
btherl Posted November 6, 2006 Share Posted November 6, 2006 Another possibility is that the udp packets are being blocked by a firewall. UDP has no setup stage, so the connection will "succeed" even if there is no path for the packets to go through. Are you able to use TCP instead? Quote Link to comment Share on other sites More sharing options...
marked Posted November 6, 2006 Author Share Posted November 6, 2006 Hi btherl,Thanks for the reply. I don't think the UDP is the issue, because I can view the page from both my localhost server (works), and my webhost server (fails) from the same machine with different results. I would have thought that if it was a firewall issue, the localhost version would also fail?I'll try the TCP connection when I get back onto my dev box, but I'm not sure how it will go, given that it's a game server I'm connecting to (retrieving server stats, player listing etc) and I think it's a UDP connection only, but I'll try it anyway.Thanks again,mark Quote Link to comment Share on other sites More sharing options...
btherl Posted November 6, 2006 Share Posted November 6, 2006 I forgot the most obvious thing to check.."fwrite() returns the number of bytes written, or FALSE on error."fread() "Returns the read string or FALSE in case of error."Once we're sure the calls are succeeding, then it's time to look at whether or not the packets are getting through :) Quote Link to comment Share on other sites More sharing options...
marked Posted November 6, 2006 Author Share Posted November 6, 2006 fwrite returns 0.........and $serverString is falseI guess what I don't understand is why that's the case with my webhost, but not my localhost. Localhost returns correct values. Quote Link to comment Share on other sites More sharing options...
marked Posted November 6, 2006 Author Share Posted November 6, 2006 Hi btherl/other interested parties.This is looking like it's a webhost problem, and I've lodged a support ticket with them. To verify this, I uploaded the full script to another host, and it works perfectly.Thank you to all who helped. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.