-
May 28th, 2013, 01:55 AM
#1
Multiple apps accesing same file on a server
Hey,
I need to implement an application that will be installed on multiple PCs. These apps need to read/write a single file on a server (which is not mine). The problem I am facing is simultaneous access to this file. The file is not necessarily a file, it is a resource, an int value, which each app will increment an bring to a maximum after which the first app to find it over the maximum value will reset it to 0. Any ideas as to how to store this value on the server and how to access it will be very helpful. Thanks in advance.
P.S. Because the server isn't mine (it's paid-for web hosting) I don't think server side code is an option. I also already have all the apps reading files from the server but each app has it's own http location so no simultaneous access happening there.
-
June 7th, 2013, 08:17 PM
#2
Re: Multiple apps accesing same file on a server
Look at LockFile() if is a shared file.
If you are talking about something on a web server that you are accessing via HTTP GET/PUT, synchronization is very difficult. Normally a separate lock file is also needed. Wait for a 0 in the lock file, write a 1 to lock the main file, get the main file value, update it, then write a 0 to the lock file so other apps can use it.
Note that you can also use a lock byte in the main file, but that is dangerous.
-Erik
-
June 8th, 2013, 03:27 AM
#3
Re: Multiple apps accesing same file on a server
Originally Posted by egawtry
Look at LockFile() if is a shared file.
If you are talking about something on a web server that you are accessing via HTTP GET/PUT, synchronization is very difficult. Normally a separate lock file is also needed. Wait for a 0 in the lock file, write a 1 to lock the main file, get the main file value, update it, then write a 0 to the lock file so other apps can use it.
Note that you can also use a lock byte in the main file, but that is dangerous.
-Erik
I'm not going to access via http get/put because I can't write to files via http. I am going to use ftp. I'll give lockfile a try. Although it doesn't seem to fix the "machines accessing the same file at the same time problem". What if 2 machines try to access the lockfile at the same time...or is that improbable?
-
June 8th, 2013, 12:21 PM
#4
Re: Multiple apps accesing same file on a server
Originally Posted by bloodfont
I'm not going to access via http get/put because I can't write to files via http. I am going to use ftp.
FTP is not a very good file sharing solution. And you will have to use the scheme I outlined for HTTP with it.
Originally Posted by bloodfont
What if 2 machines try to access the lockfile at the same time...or is that improbable?
If you use a second file as a lock file, that can still mess up, but is the best you can do.
LockFile() is only available if you have the file open on a mounted filesystem. FTP and HTTP do not fit that bill. Without server side access, you will not be able to do true file sharing.
-Erik
-
June 10th, 2013, 03:06 AM
#5
Re: Multiple apps accesing same file on a server
Originally Posted by egawtry
FTP is not a very good file sharing solution. And you will have to use the scheme I outlined for HTTP with it.
If you use a second file as a lock file, that can still mess up, but is the best you can do.
LockFile() is only available if you have the file open on a mounted filesystem. FTP and HTTP do not fit that bill. Without server side access, you will not be able to do true file sharing.
-Erik
I was thinking of designating a PC (not a server) to receive data from all the other apps, do the calculations, and respond to all the apps. Will this idea work or do I need a server?
-
June 10th, 2013, 12:33 PM
#6
Re: Multiple apps accesing same file on a server
Originally Posted by bloodfont
I was thinking of designating a PC (not a server) to receive data from all the other apps, do the calculations, and respond to all the apps. Will this idea work or do I need a server?
Then the PC IS a server.
You are talking about having another destination that handles everything properly, then it alone writes the result to the ftp server? That should work.
-
June 11th, 2013, 07:04 AM
#7
Re: Multiple apps accesing same file on a server
Originally Posted by egawtry
Then the PC IS a server.
You are talking about having another destination that handles everything properly, then it alone writes the result to the ftp server? That should work.
If this works I won't need the ftp server anymore. Thanks for your help. This seems to be the way to go.
-
June 11th, 2013, 10:11 AM
#8
Re: Multiple apps accesing same file on a server
Seems that you went with modifying the server side anyway.
Good luck!
-
June 19th, 2013, 05:36 AM
#9
Re: Multiple apps accesing same file on a server
Hi.
You can use MSMQ (or equivalent) to send notifications to the server and receive response in clients. In the server side you can use another exe to process queue menssages and update the file.
Best regards.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|