Delphi - 通过网络进行文件夹同步
我有一个连接到数据库的应用程序,可以在多用户模式下使用,多台计算机可以连接同一数据库服务器来查看和修改数据。其中一名客户端始终被指定为“主”客户端。该主站还从 RS232 或 UDP 输入接收文本信息,并每秒将此数据记录到本地计算机上的文本文件中。
我的问题是其他客户端需要从主客户端访问此数据。我只是想知道解决这个问题的最佳和最有效的方法。我正在考虑两种选择:
- 编写一个文件夹同步类,以将远程(主)计算机上的文件夹与本地(客户端)计算机上的文件夹同步。这将是一个线程化、缓冲的文件复制例程。
- 实现客户端/服务器,以便主计算机可以将此数据提供给任何连接并请求数据的客户端。主站将通过 TCP/UDP 将文件发送到请求客户端。
该解决方案必须考虑以下因素
:日志文件每秒都会被写入。它必须避免任何潜在的文件锁定问题。
b.复制例程应该只复制比客户端计算机上已存在的文件晚修改过的文件。
c.尽可能高效
D.所有机器都在 LAN
e 上。只需要例如每 10 分钟左右执行一次同步。
f.数据量仅为约 50MB,但一旦初始(第一次)同步完成,则要传输的数据量仅为约 1MB。将来这种情况会增加,
使用哪种方法更好?有什么优点/缺点?我还看到了我正在考虑使用的快速文件复制帖子。
I have an application that connects to a database and can be used in multi-user mode, whereby multiple computers can connect the the same database server to view and modify data. One of the clients is always designated to be the 'Master' client. This master also receives text information from either RS232 or UDP input and logs this data every second to a text file on the local machine.
My issue is that the other clients need to access this data from the Master client. I am just wondering the best and most efficient way to proceed to solve this problem. I am considering two options:
- Write a folder synchronize class to synchronize the folder on the remote (Master) computer with the folder on the local (client) computer. This would be a threaded, buffered file copying routine.
- Implement a client/server so that the Master computer can serve this data to any client that connects and requests the data. The master would send the file over TCP/UDP to the requesting client.
The solution will have to take the following into account:
a. The log files are being written to every second. It must avoid any potential file locking issues.
b. The copying routine should only copy files that have been modified at a later date than the ones already on the client machine.
c. Be as efficient as possible
d. All machines are on a LAN
e. The synchronization need only be performed, say, every 10 minutes or so.
f. The amount of data is only in the order of ~50MB, but once the initial (first) sync is complete, then the amount of data to transfer would only be in the order of ~1MB. This will increase in the future
Which would be the better method to use? What are the pros/cons? I have also seen the Fast File Copy post which i am considering using.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您使用数据库,如果需要共享这些数据,为什么“主”将数据写入文本文件而不是数据库?
If you use a database, why the "master" writes data to a text file instead of to the database, if those data needs to be shared?
为什么要发明轮子?请改用 rsync。 Windows 包:cwrsync。
例如,在主计算机上安装 rsync 服务器,在客户端计算机上安装 rsync 客户端,或者只是将文件拖放到项目目录中。每当需要时,客户端计算机上的应用程序应执行 rsync.exe 请求从服务器同步必要的文件。
为了复制打开的文件,您需要设置 Windows 卷影复制服务。 这里非常详细地说明了如何设置主计算机以允许复制打开的文件使用 Windows 卷影复制。
Why invent the wheel? Use rsync instead. Package for windows: cwrsync.
For example, on the Master machine install rsync server, and on the client machines install rsync clients or simply drop files in your project directory. Whenever needed your application on a client machine shall execute rsync.exe requesting to synchronize necessary files from the server.
In order to copy open files you will need to setup Windows Volume Shadow Copy service. Here's a very detailed description on how the Master machine can be setup to allow copying of open files using Windows Volume Shadow Copy.
编写一个 Web 服务接口,以便客户端连接到服务器并根据需要提取新数据。或者,您可以将其编写为订阅/推送机制,以便客户端连接到服务器,“订阅”,然后服务器将所有新内容推送到注册的客户端。客户端在注册时需要完全同步(获取自上次同步以来的所有更改),以防更新发生时它们处于离线状态。
Write a web service interface, so that the clients an connect to the server and pull new data as needed. Or, you could write it as a subscribe/push mechanism so that clients connect to the server, "subscribe", and then the server pushes all new content to the registered clients. Clients would need to fully sync (get all changes since last sync) when registering, in case they were offline when updates occurred.
这两种解决方案都可以在 LAN 上正常工作,您可以选择。您可能还需要考虑与您选择的技术相关的问题:
Both solutions would work just fine on the LAN, the choice is yours. You might want to also consider those issues related to the technology you choose: