SwiftR Posted August 28, 2012 Share Posted August 28, 2012 Hi, I have made a small script to obtain data from a call of duty game server and display it on a browser. Everything is working fine in my localhost server (Wamp Server 2.2). When I move the script to my host in bluehost.com it doesn't return any error but doesn't return an output either. I can't find out why. I am not sure if the problem is in the code, please take a look at it. <?php $connect = fsockopen( "udp://" . "85.236.102.73", "28960", $errno, $errstr, 30 ); if( ! $connect ) exit( 'fsockopen did not connect' ); socket_set_timeout( $connect, 1, 0 ); $send = "\xFF\xFF\xFF\xFFgetstatus\x00"; fwrite( $connect, $send ); fputs( $connect, $send ); $output = fread( $connect, 5000 ); if( ! empty( $output ) ) { do { $status_pre = socket_get_status( $connect ); $output = $output . fread( $connect, 5000 ); $status_post = socket_get_status( $connect ); } while( $status_pre['unread_bytes'] != $status_post['unread_bytes'] ); } fclose( $connect ); echo $output; ?> $errno returns 0 and $errstr returns nothing. I ran a fsockopen test i found on google, it was supposed to show bbc.com website title and it did so fsockopen is working. It wasn't an udp connection though so I am not sure if it is the problem. Could it be my host? What can I do? $output is supposed to return something like this: ����statusResponse \_Admin\mh170085admin\_Email\clanservers@multiplay.co.uk\_GV_strea... Please help, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/267701-fsockopen-udp-not-returning-any-output-on-my-host/ Share on other sites More sharing options...
Christian F. Posted August 28, 2012 Share Posted August 28, 2012 Why are you calling fwrite () twice? I suspect this might be the cause of your problems. Tested the (correct) code myself, and it worked for me: $c = fsockopen ("udp://85.236.102.73", 28960, $errno, $errstr, 30); if (!$c) { die ($errno.": ".$errstr); } socket_set_timeout ($c, 1000); $send = "\xFF\xFF\xFF\xFFgetstatus\x00"; fwrite ($c, $send); $output = fread ($c, 5000); var_dump ($output); // string(529) "����statusResponse\_Admin\mh170085admin\_Email\clanservers@multiplay.co.uk\_GV_streaming\enabled - CB v7.2\_Location\London, UK\_Website\http://www.multiplay.co.uk\fs_game\main\g_antilag\0\g_gametype\sd\g_needpass\1\gamename\Call of Duty 2\mapname\mp_dawnville\protocol\118\scr_friendlyfire\1\scr_killcam\0\shortversion\1.3\sv_allowAnonymous\0\sv_floodProtect\1\sv_hostname\Multiplay :: SCWTIRFLT\sv_maxclients\10\sv_maxPing\0\sv_maxRate\25000\sv_minPing\0\sv_privateClients\0\sv_punkbuster\1\sv_pure\1\sv_voice\0\pswrd\1\mod\1" Quote Link to comment https://forums.phpfreaks.com/topic/267701-fsockopen-udp-not-returning-any-output-on-my-host/#findComment-1373306 Share on other sites More sharing options...
SwiftR Posted August 28, 2012 Author Share Posted August 28, 2012 Again that script works on localhost but not on my Bluehost.com host. This time it seems to enter a loop, the page loading animation doesn't disappear and nothing is shown on the page. Edit: I fixed the loading *problem* with socket_set_timeout( $c, 1, 0 ); Now all it returns is: string(0) "" Quote Link to comment https://forums.phpfreaks.com/topic/267701-fsockopen-udp-not-returning-any-output-on-my-host/#findComment-1373351 Share on other sites More sharing options...
Christian F. Posted August 28, 2012 Share Posted August 28, 2012 Then it sounds like your host might be blocking outgoing communication. I recommend sending them an e-mail asking them about it, and if there are any possibilities to get what you need working. Quote Link to comment https://forums.phpfreaks.com/topic/267701-fsockopen-udp-not-returning-any-output-on-my-host/#findComment-1373360 Share on other sites More sharing options...
SwiftR Posted August 28, 2012 Author Share Posted August 28, 2012 Already did, I am waiting for an answer now. Thanks for your script anyway, made it simpler. Quote Link to comment https://forums.phpfreaks.com/topic/267701-fsockopen-udp-not-returning-any-output-on-my-host/#findComment-1373369 Share on other sites More sharing options...
Christian F. Posted August 28, 2012 Share Posted August 28, 2012 You're welcome. Quote Link to comment https://forums.phpfreaks.com/topic/267701-fsockopen-udp-not-returning-any-output-on-my-host/#findComment-1373377 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.