简体   繁体   English

通过网络触发事件

[英]Firing an event over a network

Where would I start with firing an event over a network? 我将从哪里开始通过网络触发事件? In my case, when I change a database record, I want to inform any other user on the network running the same application that it has changed. 就我而言,当我更改数据库记录时,我想通知运行相同应用程序的网络上的任何其他用户它已更改。

Edit: 编辑:

It's nothing clever, don't get excited. 没什么聪明的,不要激动。 I'm writing a document management system and when a document is changed in any way (deleted, checked out, up issued, etc), I want to "tell" everyone something's changed. 我正在写一个文档管理系统,当文档以任何方式(删除,签出,上签等)进行更改时,我都想“告诉”每个已更改的内容。 I was going to use a FileSystemWatcher to watch a folder on the server, sign each instance up to it's Deleted event and just create and delete a file in the watched directory, but that's just dirty isn't it? 我本打算使用FileSystemWatcher来监视服务器上的文件夹,将每个实例签名为Deleted事件,然后仅在受监视的目录中创建和删除文件,但这只是肮脏的,不是吗? As you can tell, I'm not a professional programmer :) 如您所知,我不是专业程序员:)

What kind of notification timeframe are you after? 您需要什么样的通知时间? I would personally have the client machines poll the server for updates - eg "My most recent update was on 17/02/2009 11:56:00 - what's changed since then?" 我将亲自让客户端计算机轮询服务器以获取更新-例如“我最近的更新是在2009年2月17日-从那时以来发生了什么变化?” - by implementing a webservice or simple socket-based server on the actual server. -通过在实际服务器上实现Web服务或基于简单套接字的服务器。

Otherwise, if it is a distributed app, your "simplest" bet would be a UDP broadcast - assuming they are on the same subnet and not separated by 20 degrees of routers. 否则,如果它是分布式应用程序,则您的“最简单”的选择将是UDP广播-假设它们位于同一子网中,并且不被20度路由器隔开。

Can you tell us a bit more about your situation? 您能告诉我们更多有关您的情况吗?

Each instance of your client application could be listening to a socket of messages. 客户端应用程序的每个实例可能正在侦听消息套接字。

When your server application changes the database record (on behalf of a client, or for any other reason), it also inserts a "something changed" message in the queue of messages for each client. 当您的服务器应用程序更改数据库记录(代表客户端或出于任何其他原因)时,它还会在每个客户端的消息队列中插入“已更改内容”消息。

The server application could either immediately send the message to the client application - or the client application could poll. 服务器应用程序可以立即将消息发送到客户端应用程序-或客户端应用程序可以轮询。

Have clients register themselves with a central app. 让客户使用中央应用程序进行注册。 Whenever the client updates the record it can notify the central app which then broadcast it to the registered clients. 每当客户端更新记录时,它都可以通知中央应用程序,然后由中央应用程序将其广播到注册的客户端。

Decide for yourself on transport mechanism, but you may want to consider sockets. 自己决定传输机制,但您可能要考虑使用套接字。

WCF can make this happen for you. WCF可以帮助您实现这一目标。 I have a server that sends and alarm to all the clients when something happens. 我有一台服务器,它会在发生某些情况时向所有客户端发送并发出警报。

How do you keep track of file edits? 您如何跟踪文件编辑?

I am assuming you are using a database (If not, now's a good time to set one up) - in which case, I would recommend writing an ASP.NET webservice (.asmx extension - Visual Studio can make them really easy) to communicate with this database and tell the client if any files have been modified since the last time it checked. 我假设您正在使用数据库(如果没有,现在是建立数据库的好时机)-在这种情况下,我建议编写一个ASP.NET Web服务(.asmx扩展名-Visual Studio可以使它们非常容易)进行通信使用此数据库,并告诉客户端自上次检查以来是否已修改任何文件。

Try to create a webservice for the server in Visual Studio to see how it's done. 尝试在Visual Studio中为服务器创建Web服务,以了解其完成方式。 To consume ("use") a webservice on the client machine, open up your VS project, right click on the "References" node under the project and select "Add Web Reference". 要在客户端计算机上使用(“使用”)Web服务,请打开VS项目,右键单击该项目下的“参考”节点,然后选择“添加Web参考”。

The client would need to poll the webservice, though, as it's a one-way call-response type mechanism. 但是,客户端将需要轮询Web服务,因为它是一种单向调用响应类型机制。

The advantage of this is that you needn't worry about network shares and such things. 这样做的好处是您不必担心网络共享等问题。 The disadvantage, however, is that you need an ASP.NET-capable webserver and database engine, unless they are already present. 但是,缺点是,除非已经存在,否则需要具有ASP.NET功能的Web服务器和数据库引擎。

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

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