Click here to Skip to main content
15,894,896 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have just written a window program that must access files on a network. My questions are:
Can my application read from and write to files freely in a remote shared folder?
Can my application create files in a remote shared folder?
Is access to resources like files automatically synchronized on a network e.g is access to shared files and foldes on a network automatically synchronized.
If the answer to the last question is no, then an Semaphores, event objects and Mutex
be used to synchronize access to such stated resources on a network?
If no, how can one sychronise access to resources on a network?
Posted

If you want to synchronize access, the best approach is to do a client/server architecture. The client thus never access directly the files.

Client server model (Wikipedia)[^]

Otherwise access to a file is very similar to local access from multiple programs. If one program open a file in read/write mode, typically other program won't be able to open a file with that access.

Access from multiples computer might works for files are are seldom used and not opened uselessly. It won't scale well if a lot of application works with the same files.

Also, if you cannot open a file because it is used by another computer, you would have to retry latter...
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 27-Aug-11 21:53pm    
Correct, my 5.
--SA
Sergey Alexandrovich Kryukov 27-Aug-11 22:05pm    
Additionally, I tried to explain why OP's suggestion cannot work and why your idea will. Your answer is credited.
Please see my answer.
--SA
Gbenbam 28-Aug-11 16:00pm    
I am a desk top windows programmer using native coding(not MFC). How can I employ the client\server architecture you mentioned.
Gbenbam 28-Aug-11 16:42pm    
Kindly throw light on the client/server architecture.
Philippe Mori 29-Aug-11 7:22am    
I have added a link for general description of client server model. Client/server architecture is totally different from desktop application... Also doing it in unmanaged C++ would be very low level. WCF services of web services might be a better alternative.
The answer by Philippe is perfectly correct. I just want to add an explanation.

Let's see what happens if you use the synchronization primitives you mentioned in the question. They can synchronize threads at the level of just one process, or you can use their named forms which makes them system-wide. It mean you can use them to synchronize threads on the whole system even if they are in different threads, by still in the same computer.

If you use those synchronization primitives and access a network file from just one computer using those synchronization primitives, everything will work. But who will guarantee that the same file are not used by some other computer, the one hosting the file or another remote client? Those computers has nothing to do with synchronization primitives on other computer — synchronization (for example interlocking of access to a file) will not work in this case.

You can use some network service which provided access to files for several client. As the service can synchronize access to the files on its (single) computer, this synchronization schema will work.

—SA
 
Share this answer
 
Comments
Gbenbam 28-Aug-11 16:05pm    
Does windows XP provide access to files for several clients as you mentioned in your solution?
Gbenbam wrote:
Can my application read from and write to files freely in a remote shared folder?
Can my application create files in a remote shared folder?
Yes, if your application has sufficient rights to do so. You could either setup the system to run as a specified user (eg "run as" or have it running as a windows service), or use impersonation[^] to impersonate a user credential to access the drive.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900