4

I have created a network trouble shooting tool in flash. The design will have all the componenets on the screen. I have to ping to every component once in minute. I have finished the design part.

Please someone help me how do i ping a webaddress or IP in flash.

I need a sample code.. Im using Flash CS3

Chandra Eskay
  • 2,163
  • 9
  • 38
  • 58

2 Answers2

6

In short, you can't.

In longer: you won't be able to ping, because a ping is actually an ICMP packet, and I don't believe Flash can send those. If there is some UDP or TCP service running on the machine you're trying to ping, though, AND the machine is running a socket policy server, then you would be able to use the Socket class to connect directly to that service (which could act like a ping).

David Wolever
  • 148,955
  • 89
  • 346
  • 502
  • But how do those guys developed an application on www.speedtest.net to check for speed and connectivity using a flash program. Is there any alternative? – Chandra Eskay May 06 '11 at 07:07
  • 1
    @Chandu-Indyaah: you can send request from flash app to server to make it ping address you need, then server will respond with results. – alxx May 06 '11 at 07:38
  • speedtest.net and the like use the second option I suggested: simply running a TCP service and a socket policy server (or, more likely, just using the existing HTTP server and Flash's URLLoader — I'm not sure, haven't looked too carefully). – David Wolever May 06 '11 at 17:16
4

What do you mean by you have all the components on the screen and you have to ping every component once in a minute?

If by ping you mean an app, what checks the time-response of a url, then you can try to play with this code:

var ldr:URLLoader = new URLLoader();
ldr.addEventListener(HTTPStatusEvent.HTTP_STATUS, ldrStatus);

var url:String = "URL-TO-SITE";
var limit:int = 10;

var time_start:Number;
var time_stop:Number;
var times:int;

ping();

function ping():void
{
    trace("pinging", url);

    times = 0;
    doThePing();
}

function doThePing():void
{
    time_start = getTimer();
    ldr.load(new URLRequest(url));
}

function ldrStatus(evt:*):void
{
    if(evt.status == 200)
    {
        time_stop = getTimer();
        trace("got response in", time_stop - time_start, "ms");
    }

    times++;
    if(times < limit) doThePing();
}

This is nothing special, the URLLoader tries to load the url, and listens to the response. If the status is 200, then got a successful "ping". Or pong.

On the other hand, you can always run a server-side ping program, and control that with flash.

If you mean an app, like an upload-download-speedtester, that also starts with something like this, but rather with the Loader object.

Hope this helps.

EDIT:

Preventing cache problems, you can use:

ldr.load(new URLRequest(url + "?rnd="+Math.random()));

Now, this page might not give back the exact content of a site, but might be good enough to estimate the response time. With flash.

So overall, this could clear the cache and load the site everytime to give a better result.

anemgyenge
  • 2,220
  • 12
  • 13
  • 2
    How about caching? Browser may just give cached response second time. – alxx May 06 '11 at 08:32
  • @anemgyenge : Components means pictures of various switches, routers.. they'll start blinking red if they loose connectivity – Chandra Eskay May 06 '11 at 09:55
  • @anemgyenge : My exact intention is to build an app that wil be checking components by pinging them , if they are not working then it wil start blinking red. – Chandra Eskay May 06 '11 at 10:01
  • @Chandu-Indyaah: But where are these devices located? Are these remote entities, so you have some IP addresses to them? On the other hand, if you choose flash, the solution I wrote can be a start. – anemgyenge May 06 '11 at 10:40
  • @anemgyenge : Yes they are remote, they have IPs to ping them – Chandra Eskay May 10 '11 at 07:13