Announcement

Collapse
No announcement yet.

Locking Network Users from a file.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Locking Network Users from a file.

    Hiya guys.
    I have to add multi-user functionality to an app I have wtitten,
    the problem I am having is that all users are accessing the
    current data file when the server (on which the data file lives)
    needs to move all records to another data file every 20 mins.
    How can I tell all copies of my app that are running to get out
    of the current data file, or kick them out after a delay. The app
    is run from the server so the only thing on the work station is
    a shortcut to the EXE on the server.

    This is driving me nuts.

  • #2
    If you want to "tell all" of your other programs around the LAN to do something, it will obviously involve some communication capabilities, and that will only work assuming the communication isn't hindered by firewalls.
    Rather than telling your apps what to do, how about having your file open for read and write access, and whenever a program needs to update it, it locks the file, eg:
    OPEN "c:\protected.txt" FOR BINARY ACCESS WRITE LOCK READ AS #1

    Best regards,
    Wayne


    ------------------
    -

    Comment


    • #3
      Thanks for you very quick reply Wayne.
      What I am trying to work out is...
      Client A. has a list of all records in the curent file and the
      user is browsing or responding to a record in that file, all
      of a sudden the server needs to move all records from that
      file to anothern so it can connect to another server to get
      new records, ie. the current file semi temporary; it could
      happen every 20-90mins or it could happen only once a day.
      you see what I am getting at ?

      ------------------

      Comment


      • #4
        I used following scheme.
        1) To read
        a) Open for reading; reading is allowed for all apps. Wait, if locked.
        b) Reading
        c) Close (!)

        2) To write
        a) Open for read/write; read/write for other apps is denied (Wait, if locked).
        b) Copying primary file to .Bak file.
        c) Copying from .Bak to primary file (with update).
        c) Close

        Not fast, but safety.


        ------------------
        E-MAIL: [email protected]

        Comment


        • #5
          Here is how I've done it in the past.

          First, each workstation needs to be allocated a unique number (somehow!). You could use a license-server or manually allocate these numbers... whatever works for you.

          Next, The workstation checks the server for the existance of a file (say, every 1 to 2 minutes - should be some random timeframe included), which your server app creates when it wants the workstations to halt. ie, the file acts as a semiphore. At the same time, the server creates a "response file".

          When each of the workstations finds the semaphore file, it writes an acknowledgement into the response file. This file is a random-acess file, and the workstations use their ID number to determine which record the acknowledgement is written to.

          The workstations then go into a loop waiting for the semaphore file to disappear again, checking every 5 to 10 seconds or so (again some random element is a good idea here).

          The server just needs to sit there until all workstations have responded (or some timeout occurs). The server can them do it's update and finally delete the original semaphore file.

          When the workstations detect the semaphore file has gone, they can resume normal operations.

          If one workstation does not respond to the initial semaphore, the server should be able to tell which machine it is because it's ID number will be missing from the acknowledge file. The decision to continue or alert a sysop can be made.

          Anyway, I've used this system in an automated data-gathering system in a manufacturing plant. Hopefully it may give you a few ideas to work out a suitable technique for your own apps.


          ------------------
          Lance
          PowerBASIC Support
          mailto:[email protected][email protected]</A>
          Lance
          mailto:[email protected]

          Comment

          Working...
          X