views:

76

answers:

3

This is a followup question to the one here

Here's briefly what I am trying to do. The File server creates a text file to indicate an end of the process. On a webpage on the Web Server, I loop every x seconds and make an ajax request to find out if the test file exists (ajax request to http://fileserver/files/UserFile.txt)

I've tried the following approaches so far:

  • Trigger a web method from the client side that creates a HttpContext object to verify if the text file exists. But this is too strenous on the server and I started getting all kinds of exceptions in the Event Viewer.
  • YQL works great but unfortunately it's too slow. The user waits atleast twice the amount of time.

I am looking for a solution that doesn't involve the server side. Somehow, I'd like to use JQuery to verify the existence of a text file on the fileserver.

Any thoughts?

A: 

Serving a single file from the filesystem is the most simple operation a web server can do. If that is already too much, then all other solutions will be worse. Find out why the server takes so long to serve a simple file and fix that.

Note: I'm assuming that the file is small since you say "test file". If it's a big file, the server will actually send it to the client which will need a lot of resources.

What you can try is to add an ASP page to the web site which runs code on the server that checks whether the file is there and just returns a tiny piece of HTML which you can add to the page with jQuery.load().

Aaron Digulla
@Aaron - YQL takes a long time as my code needs to talk to a third party which in turn adds overhead. Doing HttpWebRequests on the server takes a long time because 1) it's doing it on the server and 2) I have to loop every few seconds for each user and this adds strain on the server
A: 

You should be able to use JSONP and JQuery.ajax() to do cross-domain request work. Play with the jsonp and jsonpCallback attributes. Alternatively, you can use JQuery.getJSON().

justkt
@justkt - AFAIK jsonp requires a server side page (aspx.cs) on the fileserver that makes a request and return a json string. My file server is not ASP.NET enabled.
What does that mean? JSONP does not require any such thing. All it needs is for you to be able to modify your server side results so that you get back jsonpCallback({ yourData }) as opposed to { yourData }.
Ollie2893
@user102533 - as @Ollie2893 says, you can serve up JSONP in all sorts of ways. Just as long as you return the correct JSONP syntax (as documented in my link), it'll work. File presence or absense should be pretty simple - just send something that fires off a script on the server to do a find on that file and return true or false as your data in JSON format.
justkt
I guess I am confused. Can you please update the answer with a code snippet? Thanks
I am not convinced that JSONP is the answer. I find the idea of a browser polling a server long-distance abhorrent. Since you have these x-domain problems anyway, why not solve the whole problem using a proxy relay on your domain server? Let the client fire one Ajax request at the proxy, and then let the proxy do the medium(?)-distance polling (still horrid).
Ollie2893
The JSONP snippet you need goes like so: JS client: $.ajax({ dataType: "jsonp", ... }); PHP server: exit( $_REQUEST['callback'].'('.yourCurrentReply.')'); That's it. BUT be careful! jQuery JSONP has NO error handling (1). All JSONP requests are of method GET (payloads < 2K). (1) Check out http://code.google.com/p/jquery-jsonp for a somewhat better implementation.
Ollie2893
@Ollie2893 - I could see doing Comet from the web server to push to the browser and on the server going to the other server - that could definitely work.
justkt
A: 

I may be miles off base here but... could you not create ONE asynchronous (!) Ajax client request with a HUMONGOUS timeout. Fire it, and wait. You would be invoking some server script that checks every so often, in a loop on the server (using sleep in between), whether the file exists. And not replying to the Ajax request until the file finally shows. The server script then replies and exits.

EDIT: Depending on the server-side scripting framework used, you may even get some OS support. You may be able to sleep on a status change in the directory...

Ollie2893