网络上的资源访问是否自动同步? [英] Is access to resources on a network automatically synchronized?

查看:64
本文介绍了网络上的资源访问是否自动同步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚编写了一个窗口程序,该程序必须访问网络上的文件.我的问题是:
我的应用程序可以自由读取和写入远程共享文件夹中的文件吗?
我的应用程序可以在远程共享文件夹中创建文件吗?
对资源(如文件)的访问是否在网络上自动同步,例如对共享文件和网络上的折页的访问是否自动同步.
如果最后一个问题的答案为否",则表示信号灯,事件对象和Mutex
用来同步访问网络上此类指定资源?
如果没有,如何同步对网络上资源的访问?

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?

推荐答案

如果要同步访问,最好的方法是建立客户端/服务器体系结构.因此,客户端永远不会直接访问文件.

客户端服务器模型(Wikipedia) [
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...


Philippe的回答是完全正确的.我只想添加一个解释.

让我们看看如果使用问题中提到的同步原语会发生什么.他们可以仅在一个进程级别上同步线程,也可以使用它们的命名形式使它们在系统范围内同步.这意味着即使它们位于不同的线程中,也可以使用它们来同步整个系统上的线程,即使它们仍在同一台计算机上.

如果您使用这些同步原语,并且仅使用这些同步原语从一台计算机访问网络文件,那么一切都会正常进行.但是谁能保证同一文件不会被其他计算机(托管该文件的计算机或另一台远程客户端)使用?这些计算机与另一台计算机上的同步原语无关—在这种情况下,同步(例如,互锁文件访问)将不起作用.

您可以使用某些网络服务,该服务为多个客户端提供了对文件的访问.由于该服务可以同步对其(单个)计算机上文件的访问,因此该同步架构将起作用.

—SA
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


Gbenbam写道:
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?

是的,如果您的应用程序具有足够的权限可以这样做.您可以将系统设置为以指定用户身份运行(例如,运行方式"或使其作为Windows服务运行),也可以使用^ ]来模拟访问该驱动器的用户凭据.

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.


这篇关于网络上的资源访问是否自动同步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆