I need to ping to an network with flash or actionscript

十年热恋 提交于 2019-11-29 07:54:26

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.

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).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!