• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help needed to compare timestamp

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I needed some help on how to compare if a file on the server is modified. I wud like 2 explain what I am looking for. Hope this explains.
I have created a server socket n a client socket. Whenever the client connects to the server it downloads some files for the first time. Now if later the clinet again connects to the server, and if there has been an update on these files on the server, then the client must download them. Else the client shud not download those files.
My problem is I am unable to acces the file on the server to read its timestamp . Is there any way to read the file information on the server thru the socket.
Well, I am able to download the file without any hassles. But am unable to find if the server files has been modfied or not.
Can anyone help plz.
Thanks in advance for ur time
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
java_wizard
Welcome to the Java Ranch, we hope you�ll enjoy visiting as a regular however,
your name is not in keeping with our naming policy here at the ranch. Please change your display name to an appropriate name as shown in the policy.
Thanks again and we hope to see you around the ranch!!
 
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't know how check that a file has changed the way you are asking.
Maybe you could download the file and check it against the one you got last time. Or have a daemon on the server which would keep track of the files and if they change make a notation in a different file - which you could download first to determine which of the files had changed.
 
arch123
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dont want 2 download the file if there are no changes. Only if there are any wud I download. Isnt there any way for me to check atleast for the size of the file if not the timestamp.
Coz my main objective is to only download those files for updation on client only if there was any modfication on server.
 
William Barnes
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Example 17.7 MkIndex.java in Java Cookbook creates a web page that is a directory listing. Maybe that would point you in the right direction. You can download the all examples from the book here: Java Cookbook
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
arch123
Thanks for changing your name, however, it still does not meet the naming requirments. Your display name should be a first and last name separated by a space. You can use the link in my post above to change it.
thanks
 
arch123
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This link seems to be quite in depth. A good link though but couldnt find exactly want i needed.
I am working on a java applet now. This applet is however residing on my server. I wud want 2 invoke this applet locally . For that , I create a serevr socket n a client socket for downloading the jar files n other related files from the server.
Now I am able to do the downlaoding part. So at present I am having my applet's jar file on my hard disk on my local machine. Now whenever there is any changes made to the applet on the server , I want the clinet machine"(my local machine)to detect the changes in the jar file n download the jar again to my local machine.
For this I was wondering if I cud check for the timestamp of my local machine's jar file and that on the server. Thereby , if they dont match then it indiactes that server files have been modified recently.
The problem is how to check for the timestamp or say how do i check if the file on the server n that on my local machine are similar or not.
Hope this explains
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Comparing timestamps is not completely reliable in detecting changes to a file. You can compare checksums of the file, using a md5 or crc32 checksum to determine if the file has changed.
You could do something like this:
1. The client calculates the checksum of it's files.
2. The client sends the checksum to the server.
3. The server calculates the checksum of it's file and compares it against the checksum that the client sent over (the client's checksum).
4. If the checksums do not match, then the server must have a newer file, send the file to the client.
As for the java code to calculate the checksum, you can probably find something using a search engine since I haven't done this before in java.
java.util.zip.CRC32 in the JDK and http://www.ietf.org/rfc/rfc1321.txt might get you started.
Eddy
 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about looking at URLConnection.getLastModified(), which will give you the last-modified header value from the web server. Your web server should support filling out this field based on the file's modified timestamp.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic