简体   繁体   English

在PC之间在Delphi中共享公共内存区域

[英]Sharing a common memory area in Delphi between PCs

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. 我有一个Delphi 2006应用程序,它收集数据并将其显示为许多通道的摘要,在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. 我有相同的应用程序在网络上的各种其他PC上运行,但这些其他PC是从属 - 它们不收集数据,而只是提供摘要的远程显示。

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)? 我可以使用一些共享内存方案将数据放到内存映射文件中,从而可以从任何地方(通过Web,甚至)访问从属设备吗? 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. 我们讨论的最大内存大小为100k字节,比如说,主机每秒大约一次更新,可能是在一个线程中,以保持主前台任务的响应。

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). 共享内存不能通过Web工作(除非你运行VPN),并且它通常不能在网络上正常工作(视图可以被去同步,你无法通过网络同步它们)。

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. 选项1.使用面向消息的中间件(MOM),例如MSMQ,kbmMW,我们的MsgConnect来广播仅包含数据更改的通知。 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. 所有MOM解决方案都使用TCP连接进行操作,这比邮件槽更可靠。

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). 选项2.使用一些客户端 - 服务器DBMS,可能是支持客户端通知的那个(我不是DMBS的专家,所以我不能告诉你名字)。

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. 您可以使用DBISAM,Firebird等数据库。使用DBISAM,我使用了读取数据库文件的前8个字节的技巧,这似乎是一个标题。 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. 如果使用轮询循环,或者如果要继续使用邮件槽作为通知方法,则可以在客户端中使用此功能。 ie poll the file every 10 seconds or upon mailslot notification, whichever comes first. 即每隔10秒或在邮件通知时轮询文件,以先到者为准。

What's wrong with using TCP/IP? 使用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. 你可以使用Indy (已经附带Delphi)或ICS让你的主(主)应用程序用一两个线程响应IP请求(例如,HTTP或ICMP或任何适合你的数据需求),并拥有“奴隶” “应用程序只是通过特定端口上的主服务器的IP地址请求数据。 This would work on an intranet or via the internet transparently. 这可以在内联网上或通过互联网透明地工作。

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 (eg a daetabase server or some middleware) following the KISS principle. 使用简单文件的优点是它不需要遵循KISS原则的任何其他软件(例如daetabase服务器或某些中间件)。 But of course it is far from sexy ;-) and does not use the correct buzzword technology. 但当然它远非性感;-)并且没有使用正确的流行语技术。

我们使用MSMQ来做类似的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM