I have been working on a desktop app using AppJS (HTML5, JQUERY). In my application, I ask user to input a folder path of his/her local machine (where application is running) and store that info in my database on the server.
I have to push a file to that folder (on the user's machine) whenever the file gets updated on the server. how can I achieve this? how I can keep client and the server in sync so that server can push that file to local machine.
I have written the scheduler app for the server which will push the file down to client. But, I am not getting how to push that file to specific client. what parameters I need to push the file to client like client's machine MAC Address or something else.
how dropbox does sync?
Please help!!!
If you are able to run nodejs on the server then you can use socket.io to communicate between client and server. Think of it like a chatroom like msn or skype. As users open the appjs application it can connect to the server.
When you have a file to push send a message like "updatedFile" and then list the url. Clients can then download the file and save to the local disk.
This way all connected clients can download updates and no need to poll all of the time - just have websocket open.
When a client connects it could send a message changesSince timestamp and receive a list of all files changed on server since that time which it can then download and save to local disk one by one.
You can try using tools like rsync which can directly help you achieve this.
http://en.wikipedia.org/wiki/Rsync
Related
How to update an MDB file from other machines remotely over the HTTP?
I have 2 machines that are connected by the internet, on the first, I have an MDB file and on the other, I have a java web application, I want to send an SQL query from the java web application to update the MDB file on the other machine over the HTTP.
I tried to use FTP, but it is transferring the whole file b
A file such as word, or power-point or Access?
Well, a horse is a horse is a horse.
A file is a file is a file.
You don't connect to a word file to update it. You don't connect to a Excel file, or a power-point file. And you don't connect to a Access file. You OPEN a file, and THEN modify it. You can't open nor modify files over FTP, nor can you modify them over HTTP either. And you can't even do that with a plane jane text file. These are files - you have to open them to modify them. Or pull a whole copy to one side. Update that file, and then send it back.
So, you don't want to confuse the concept of a simple file, or file based system like say a text file, excel file, or Access file. These are NOT servers or say a service that you connect to. You never open a MySQL file - you connect to a server + service via tc/ip (a socket conneciton) and then send commands back and forth. You NEVER open or touch that MySQL data file. The server updates that file - not you, and not your code.
So, Access is not a server based, or socket connection based service. It is a file based system - not un-like a text file. You don't connect to a text file, you HAVE to open that file - modify it and then save it. You can't do that over http. In fact you can't even do that with FTP either. You can pull the whole file, modify and then send it back to where you got that file from.
Now, you could however setup + create some web service calls or entry points on the one site. You could send that web site some commands, and then code behind on that web site can open up that text file, word file, or in this case the Access file and make changes . But once again, just like MYSQL or say the web server? You not opening the remote file direct - are you? You are (and can) thus setup some code or web methods (even REST ones) that accept commands, and those (even sql update commands) could then be run by that remote server/service and thus update the file on that target system. In the case of Access data files?
If you look VERY close, even a ODBC connection string ALWAYS ALWAYS resolves to a valid windows path name (and a full legal qualified windows path name at that).
so, while there is a ODBC driver, the software driver still in fact uses a standard windows OS file open command against that plane jane file sitting in the hard disk. So to update that Access file, you need the driver - since it knows how to open that file, and how to update the delicate data file structures inside. So, even via ODBC? Well, it not a socket connection and you not connecting to a server on the other end - but in fact opening a simple windows file. In fact this means that you not only require DIRECT file rights to that access data file - but you actually need the windows file system!
However, sqLite is the SAME thing. There are thus some jdbc drivers. This JDBC concept is VERY similar to ODBC, but is for web based systems. You install a library on one end (where sqlite resides), and then that web service can take your sql commands (updates or query pulls), and thus the web site code now opens that local file, executes sql against it, or does a query pull , and then returns the results of your query - and the web query calls are done via that web service (rest calls) on that server. So, you can in theory shuffle commands between two web servers - and there are some types of "drivers" such as jDBC standards that in theory do wind up giving you a similar experience to ODBC.
In my webapp users can download the files among themselves. If a user A has shared a file F , then user B after connecting to A can download the file F from A. Till now each user makes a simple HTTP connection like :xxx.xxx.xxx.xxx/FileList with another user. The file resides on the local hard disk of each user. So that a user can download a file there were two options in my mind.
As the user shares a file,copy that file into the web-app directory of the server,so that the download link becomes as simple as Click to download.
Run a separate FTP server on each node.
I don't know which one of these is a better option but the first one seems very simple to me. What are the ways each client can share the files,without having to copy the stuff somewhere in the webapp directory. How in this case I can use a P2P protocol ?
NOTE : I am using Tomcat 7.
Real P2P is impossible without opening a listening socket on the client machine (that imposes you have to install something on client machine).
If you don't want to STORE the files on the server, I would rather recommend a "connection server", which serves as a gateway between the two users. User A will upload, user B will download at the same time, all you need is to make the bytebuffer in memory. The downloaded bytes can be dropped.
You can write a small client-side program in any language for updating the available files, and receiving the upload request from the server side (also execute the upload)
I would recommend using TCP sockets for upload to the server side, this way you have direct control over the uploaded bytes (streams).
There are some interesting technical issues here (blocking streams, metadata (filename, length, createdate, ...), data consistency, error handling, etc.) that should be taken into consideration. Nice task.
I don't recommend FTP because you cannot control the authentication and authorisation (who can see the files).
I have several PC's on each of them I set small swing application that get data with JSON request to one web server. Can I receive the data from web server without to send request to the web server, with other words can the Web server send the data without the Java application to ask for this?
If you have enough server resources
you can consider usage of websockets.
Every PC can open a socket to the server.
When you open the socket you need to send to the server, the pc's unique ID.
Then you need to store this ID in some database or file that will contain all online pc's and sockets .
Then the Server will be aware which pc's are online and which socket to use to communicate with this pc. After this you can send whatever information you need to this PC depending on your application.
This can be implemented in several ways. One common way would be to open a connection and do blocking read in the client application. On receiving something it will look like push from the server. Then you process the push and do another blocking read.
Another option would be doing regular checks if there is something for you on the web server. You set the retry interval frequent enough so it will look like real time push from your app point of view.
If you use HTTP i think the smartest way is to drop the realtime requirement and use a thread that polls the server every 5 seconds. Keeping a HTTP Connection open all time is expensive as it blocks a request processor thread and limits the amount of clients you can have.
You might also consider moving to something like a registration mechanism if you really need near-realtime updates which is often not the case. You would have to open a Server on the clients and have the server push the updates after clients registered their Address with the server.
I have been trying to write an app that generates a personal WiFi hotspot from an android device, that funnels webpage and file download requests through the host's mobile data connection. I have managed to request and download the files, but they are being stored under the phone, on the sdcard\toSendOverWifi\ folder I created.
Quick list of activities done:
Recieving device sends webpage/file HTML address request to host
Host downloads file over 3g/4g/LTE data connection
Host saves file(s) to sdcard\toSendOverWifi\
(not done) host sends file out to recieving device (only connection)
Ihave not found a class and/or method to send the downloaded files over WiFi to other devices.
What class/method do I need to accomplish this? And is it compatible with non-rooted devices?
You need to use TCP/IP sockets as usual.
My question is about reading a remote XML file by using Java.
My files are stored in one device that runs Windows CE. I should access to few of these devices several times per day.
Which solution is more efficient considering network constraints, stablishment of a TCP session and data loss: to open and read the file remotelly or get a copy locally to the server and process it then?
Thank you very much.
It seems u want the files to be read from client by server, whereas it most cases its the other way round. In this case you should have some push functionality from the client to server and this can be over HTTP.
Or you can have a Http connection listener running in the client which accepts request from server and sends back the XML file to the server. Essentially its like a server thread running in the client.
Not sure if u running JAVA on Windows CE. Look for solutions in Windows CE HTTP listener.
See if it helps