Go Back   kirupaForum > Development > Client-Side (HTML, CSS, JavaScript)

Reply
 
Thread Tools Display Modes
Old 11-19-2009, 01:04 AM   #1
Kevin Evans
Registered User
Check if server is online?

T-T
I can't figure this out. I'm trying to check if a server is online, and I need to do it efficiently. I have no idea where to start, i've tried AJAX, but it doesn't really check if the server is online (it only checks if the URL is malformed)

I know somebody knows how to do this!!

So... anyone wanna help me fill this out? :3

Code:
function serverOnline(var server){

return false;
}
<3
thanks
Kevin Evans is offline   Reply With Quote

Sponsored Links (Guests Only) - Register | Need Help?
 

Old 11-19-2009, 09:12 AM   #2
Swooter
Swooter - AS/JS/HTML/CSS
 
Swooter's Avatar
You could use a PHP script like this:

pingdomain.php
PHP Code:
<?php
 
function pingDomain($domain){
    
$starttime microtime(true);
    
$file      fsockopen ($domain80$errno$errstr10);
    
$stoptime  microtime(true);
    
$status    0;
 
    if (!
$file$status = -1;  // Site is down
    
else {
        
fclose($file);
        
$status = ($stoptime $starttime) * 1000;
        
$status floor($status);
    }
    return 
$status;
}
echo 
pingDomain($_GET["domain"]);
 
?>
And then load it with xmlhttp:
pingdomain.php?domain=www.kirupa.com

and then check whether the responseText is 0 or -1

__________________

AS / JS / HTML / CSS / PHP
Swooter is offline   Reply With Quote
Old 11-20-2009, 12:46 PM   #3
actionAction
humanBeing._beard=true;
 
actionAction's Avatar
Use jQuery ajax call with the timeout variable set:

HTML Code:
function checkServer(server){
    //assume it is not online
    var active = false;
     $.ajax({
        url: 'http://www.'+server,
        timeout: 3000, //set the timeout to 3 seconds
        success: function(){
            active = true;
        },
        error: function(req, err){
           if(err == 'timeout'){
              console.log('Server: %s timed out', server);
           }
        }
     });
     return active;
}

__________________
help = (!(poster.do_my_homework || poster.not_trying )) ? yes : no;
actionAction is online now   Reply With Quote
Old 11-20-2009, 01:24 PM   #4
actionAction
humanBeing._beard=true;
 
actionAction's Avatar
Nevermind, I am braindead. You can't do remote XHR requests, duh! Anyway, if there is a static set of servers and you are wanting to keep this in Javascript, you can look for an image (that you know will exist) and see if it is there or not:

HTML Code:
    var img = new Image();
    //This is a yahoo image
    img.src ='http://l.yimg.com/a/i/mntl/ww/events/p.gif';
    img.onerror = function(){
        console.log('Problem loading remote image');
    }

__________________
help = (!(poster.do_my_homework || poster.not_trying )) ? yes : no;
actionAction is online now   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:34 PM.

SUPPORTERS:

kirupa.com's fast and reliable hosting provided by Media Temple. flash components
Creative web apps. Make your own free flash banners and photo slideshows.
Check out the great, high-quality flash extensions. Buy or sell stock flash, video, audio and fonts for as little as 50 cents at FlashDen.

Flash Transition Effects

Flash Effect Tutorials

Digicrafts Components
Flash effects. Art without coding. Upload, publish, deliver. Secure hosting for your professional or academic video, presentations & more. Screencast.com
Streamsolutions Content Delivery Networks Flipping Book - page flip flash component.
Flash-Gallery.com - Get your flash photo gallery (flash component or swf gallery Learn how to advertise on kirupa.com
 

cdn
content delivery network (cdn)

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd. Copyright 2010 - kirupa.com Copyright 2010 - kirupa.com