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?
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().
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().
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...
Related
I have a C++ project for windows, using MiniBlink as embedded browser. (MiniBlink is a smaller Blink, which is close to chromium). I use this embedded browser to show responsive and nice looking dialogs with Quasar.js (wrapper for vue.js).
Problem:
Mostly a browser is just the passive backend. In my case, both the backend (project with embedded browser) and the frontend (dialog) are active and thus I need some communication. At the moment I use a local server to catch HTTP send from the frontend to the backend.
But is there a way to communicate from the backend to the frontend? At the moment I could only think about catching cookies or using a permanent loop in JS to send http queries to check for a possible response.
And is there no other way to send information to a backend? Everything is local, I dont need nor really want to send it into the network.
Thanks!
Idea 1: Use a local temp file to save on one side and read on other (can be also used both way)
Idea 2 (similar to question author solution): Local server with both side communication (GET/POST request into one side, text/json other way around)
Idea 3: Use launch parameter to pass though data directly into links for example: instead of using browserprocess.exe file.html, use browserprocess.exe file.html#showsomething
There are also other ways which like catching for example: checking window title of process with certain binary name from running tasks by other side; we didin't get good enough info about your background becouse you coud either use it in same process or other process, if thats same process you coud also just directly use variables both ways directly in code of miniblink and do action when they meet if statement
As CertainPerformance added as a comment, WebSockets might be the best way to go.
If one does not like to implement a websocket server, because a http server is already running, long polling requests might be the best workaround to simulate this behaviour.
Long polling: The client sends a request, which stays open as long as possible. If the server needs to communicate, it can use the open request to send its own "request" via response. It is a bit hacky, but essentially the idea behind websockets.
Mozilla has a nice article to help with websockets:
https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_servers
If you (like me) use vuejs or quasar, you might want have a look at vue-native-websocket.
https://github.com/nathantsoi/vue-native-websocket
Good luck
I have shared folder between in my server which will allow other server to send XML file to me and I want my script read this file auto without opening any page.
I know how to open and read the file.
But the issue how to auto load in the backhand.
you have to create a one page which will read the provided file and do the required actions , then share this URL and format with the team who will going to provide you the xml file.
It is very much like API Endpoint, Where you have to write the code which will handled request and in this scenario your Endpoint will treat as a server and XML file provider will treat as clients.
I hope this answer helps u.
Thanks
Traditionally, you need your server to periodically execute the script which reads the XML. That PHP will need to parse the XML and handle the changes.
Alternatively, the source of the API can use push notification to avoid polling with your server. The XML will be received whenever a change occurred on the server without the creation of a lot of useless requests, but the XML will be parsed as in the previous approach.
Last, but not least, you can use WebSockets for this purpose, or if both computers are in the same network, you can use sockets. Off course, a lot depends on the data source, whether you have access there, how modern is its technology and what does it allow you to do.
I've got a local XML file constantly updated by 3rd. What I would like to achieve is a web page that constantly read and show one xml tag without refresh the page. Plus I would like to trigger an event when XML value change.
What language I should use? I've read something about ajax, it could be ok to build a script like this?
You can not read file from filesystem using only javascript related post
You need a web server like Nginx or Apache HTTP which will serve the file to a client using http request. related post
Finally you will need to implement poll request using ajax on client-side to check the file once per specified interval (for example 10 seconds) related post
NOTE: Check jQuery, it can simplify your life
Suppose I have server. A client loading an HTML file containing a javascript library will have the script executed by the browser. The problem here is that if the client's computer is slow, the processing will take a long time.
So I want to move the processing to the server side. But, instead of having to rewrite the entire javascript library into another language, I simply want to run the javascript on the server.
Googling "server side javascript" directs me to Node.JS, which in my imagination have the capability to do so. But, I cannot find a tutorial which does just that. Does this mean that there really is no easy way to do so? For example, because the javascript script may contain DOM specific things such as document.getElementById(), which does not make much sense on the server side.
There is no trivial way to simply shift processing of JS from the client to the server.
You need to break the code down into code that must run on the browser (such as, assuming you don't want the browser to load an entirely new page, DOM manipulation) and code that can run on the server.
Then you need to provide a way to pass data between the server and the browser, this is normally done via HTTP (using Ajax).
When you take input from the client you need to send it to the server in an HTTP request (instead of just passing it as an argument to a function). The server needs to read the HTTP request, process it, and make an HTTP response.
The Ajax callback then needs to parse the response and run any client side logic (such as DOM updates) in response.
Note that network communication times will impact performance.
You can't "merge" the client and server in this way. All you could do is process the data on the server and just display it in the client without any further processing. Maybe you should refresh you knowledge about HTTP and how websites are send to the clients. Without any additional tricks, like websockets, comet or ajax polling, you can't access the client after you send the initial website to it. Even than you can just send data to the client.
When you want to stick to Javascript, Node.js is a good option. But even than you would need to send the data you want processed to the server, process it there and send back the processed data in JSON or "display ready" HTML.
I have a system where I inject a script tag into the dom.
The browser tries to load the script url, which is actually a long-post to a Tornado server.
I'm trying to implement an "abort" feature, where I stop the long poll. I need to do this because I am long-polling multiple different URL's which eventually exhausts the browser's socket pool for my server.
I have tried removing the specific script node from the DOM, but the browser is stubborn and continues waiting for a response from the server.
Is it possible to tell the browser to stop trying to load a resource (specifically a javascript file) once I've included it into the DOM?
You could try an asynchoronous abort "mission" and kill the pid of the request. Thsi kind of tehnique is very similar to this post Cancel PHP script with XHR? so you could run an extra ajax call for an abort which handles it like in the post above. Happy new year!