Read the file ...before actual write ??..or the last written data

Posted on 2007-08-01
Last Modified: 2011-09-20
what i want to build is a log file monitor...or rather a virtual logfile monitor.

My problem is as follows.
I have an server and clients spread all over the network. I do not want to use winsock due to certain restrictions.
All the clients have write acess to a certain directory on the net work.

what i want to do is some thing like this.
when the server wants to a send a command to a specific client it will write into the \command\<MAchineName> file
the client need to detect this change and get what is what was written and take actions..
and report in

now  I have looked into these solutions

what i want to know is it possible to read what is beind written ..before it is acctually wriiten on the disk...either on the local or remote machine.
I know i can detect a file modify. but is it possible to detect what was being written so that instead of parsing the entire file...which may become very very big since it is a 24/7 application ...i only get what was the last written thing???

Question by:mandelia
    LVL 142

    Expert Comment

    by:Guy Hengel [angelIII / a3]
    if you really want to make the process safe using files, you need 2 files each time:

    1 file containing the command
    1 file containing the acknowledge that the command file is complete.


    so the server has to write the .txt file first, and then only the .ack file.

    the client has then to check only if there are .ack files, and for each .ack file, get and process the corresponding .txt file.
    and once it has processed the file, delete both the .ack and the .txt files.

    so, do NOT create 1 file per client, but 1 file per "command".
    LVL 5

    Author Comment

    Actually that is exactly what i want to avoid...
    Please check the solution which i have attached ..
    what i want to do is to "intercept the write" if it is possible....
    meaning when the file is being written on the disk the data which is written come .i am able to peek into it..

    if this is not clear let me try to explain it with an example.
    Consider a client ABC , and DEF using the directory \logs
    when the serven wants to send a command to the ABC ..
    it appends the COMMAND to the end of COMMAND.ABC.log

    if it wants to send the command to DEF then
    the server then it append the command to the end of COMMAND.DEF.log

    consider the example in the links given above ..i can easily detect whan a change has occured in a given file...i.e some thing has written into it...

    in a normal way ..yes i would chek the ack file if it exists and tht menas the server has finished writing
    and  then i can read to the end of the file to process the command....

    two resoan why i do not want to do this
    1) There may be multiple commands .one after the other
    ..therefore..there is a chace of a clash

    LVL 5

    Author Comment

    2) i do not want the client to delete the files...since i want the server to have them open though out the session

    what i am trying to do is to basically be able to peek into what the server is writing ...while it is writing or just after it is finished.

    Is this possible...or do i have to read to the end of the file everytime...
    LVL 142

    Accepted Solution

    then, you will need to use some pipe/queing mechanism (like MSMQ or the like).
    you cannot intercept a file write, although you can detect that a change happens.
    LVL 5

    Author Comment

    hmmm.....thank you for that answer....

    I have already tried winsock..and failed due to too many no of clients... and other issues ..

    is there a better messaging method....(MSMQ not supported) that u can think of?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
    You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now