在 PC 之间共享 Delphi 中的公共内存区域
我有一个 Delphi 2006 应用程序,它收集数据并将其显示为许多通道的摘要,TDrawGrid 上每行一个通道。我在网络上的其他各种 PC 上运行相同的应用程序,但这些其他 PC 是从属设备 - 它们不收集数据,而只是提供摘要的远程显示。
目前,从站仅在主站上显示摘要显示屏幕的模仿,这是通过主站的邮槽的广播来实现的。
我想以不同的方式实现这一点,以减少主站的负载,并为从站提供更多的灵活性和独立性来解释数据。另外,我在跨子网数据的邮槽广播方面遇到问题。
我可以使用某种共享内存方案将数据放置到内存映射文件中,从属设备可以从任何地方(甚至通过网络)访问该文件吗?我们讨论的是最大 100k 字节的内存大小,例如,由主站大约每秒更新一次(可能在线程中),以保持主站前台任务的响应。
I have a Delphi 2006 app that gathers data and displays it as a summary of many channels, one channel per row on a TDrawGrid. I have the same app running on various other PCs on the network, but these other PC's are slaves - they don't gather data but merely provide a remote display of the summary.
At present, the slaves just show a mimic of the summary display screen on the master, and this is implemented via broadcasts by way of mailslots from the master.
I want to implement this in a different way, to reduce the load on the master, and provide the slaves with a bit more flexibility and independence on how they interpret the data. Also, I am having issues with mailslot broadcast of the data across subnets.
Can I use some shared memory scheme to lay the data down to a memory-mapped file where the slaves can have access from anywhere (over the web, even)? We are talking about a memory size of 100k bytes max, say, updated by the master at around once per second, probably in a thread, to keep the master foreground task responsive.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
共享内存无法在网络上工作(除非您运行 VPN),并且通常在网络上工作得不好(视图可能会不同步,并且无法跨网络同步它们)。
我可以看到针对您的任务的几种解决方案:
选项 1. 使用面向消息的中间件 (MOM),例如 MSMQ、kbmMW、我们的 MsgConnect 来广播仅包含数据更改的通知。这样客户端就不需要另外轮询服务器来获取数据快照。所有 MOM 解决方案都使用 TCP 连接进行操作,这比邮槽更可靠。
选项 2. 使用一些客户端-服务器 DBMS,可能是支持向客户端发送通知的 DBMS(我不是 DMBS 方面的专家,所以我无法告诉您名称)。
Shared memory won't work over web (unless you run VPN) and it doesn't work well over network in general (views can be desynchronized and you can't synchronize them across network).
I can see several solutions to your task:
Option 1. Use message-oriented middleware (MOM), such as MSMQ, kbmMW, our MsgConnect to broadcast notifications which include only changes in your data. This way the clients won't need to poll the server additionally for data snapshot. All MOM solutions use TCP connections for operations and this is more reliable than mailslots.
Option 2. Use some client-server DBMS, probably the one which supports notifications to clients (I am not an expert in DMBS so I can't tell you the names).
最简单的方法是使用共享上的文件,主服务器只能写入而从服务器只能读取。如果您想防止“脏读”,可能需要某种同步。另一方面,这可能并不重要,具体取决于您想要显示的数据类型。
使用简单文件的优点是它不需要遵循 KISS 原则的任何附加软件(例如数据库服务器或某些中间件)。但当然它远非性感;-)并且没有使用正确的流行语技术。
The simplest way is using a file on a share that the master writes to and the slaves only read. Some kind of synchronization might be necessary, if you want to prevent "dirty reads". On the other hand, it might not matter, depending on the kind of data you want to display.
Using a simple file has the advantage that it does not require any additional software (e.g. a daetabase server or some middleware) following the KISS principle. But of course it is far from sexy ;-) and does not use the correct buzzword technology.
您可以使用 DBISAM、Firebird 等数据库。
使用 DBISAM,我使用了读取数据库文件的前 8 个字节的技巧,这似乎是一个标头。如果它改变了,我就知道表中的数据已经改变,否则它没有改变。如果您使用轮询循环,或者如果您想继续使用邮槽作为通知方法,则可以在客户端中使用此功能。即每 10 秒或根据邮槽通知轮询一次文件,以先到者为准。
You could use a database such as DBISAM, Firebird, etc..
With DBISAM, I've used a trick of reading the first 8 bytes of the database file which seems to be a header. If it changes, I know that the data in the table has changed, otherwise it hasn't. You can utilize this in the client if you use a polling loop, or if you want to continue to use the mailslots as a notification method. i.e. poll the file every 10 seconds or upon mailslot notification, whichever comes first.
使用 TCP/IP 有什么问题?您可以使用 Indy (已随 Delphi 一起提供)或 ICS 让您的主(主)应用程序通过线程响应 IP 请求(例如 HTTP 或 ICMP 或任何适合您数据需求的内容)或两个,让“从属”应用程序仅通过特定端口上的主应用程序的 IP 地址请求数据。这可以在内联网上或通过互联网透明地工作。
What's wrong with using TCP/IP? You can use Indy (ships with Delphi already) or ICS to have your main (master) app respond to IP requests (eg., HTTP or ICMP or whatever suits your needs for data) with a thread or two, and have the "slave" apps just request the data via the IP address of the master on a specific port. This would work on an intranet or via the internet transparently.
我们使用 MSMQ 来做类似的事情。
We use MSMQ for something similar.