简体   繁体   English

C#客户端到客户端消息传递

[英]C# Client to Client Messaging

I will try and explain exactly what I want to achieve first. 我将尽力解释我首先要实现的目标。

Imagine two users are using a windows forms application, when User A opens a particular form a lock is applied to the data record underlying the form so that only that user can make changes at that time. 想象有两个用户正在使用Windows窗体应用程序,当用户A打开一个特定的窗体时,会将锁应用于该窗体下的数据记录,以便当时只有该用户可以进行更改。

User B has a list of all records (in a grid) which among others contains a reference to the record already opened by User A. What we want to do is when User A opens the records User B's list of records is updated to show a lock icon next to the row to indicate the record is in use. 用户B拥有所有记录的列表(在网格中),其中包括对用户A已经打开的记录的引用。我们要做的是用户A打开记录时,用户B的记录列表已更新为显示该行旁边的锁定图标以指示该记录正在使用中。

This is a trivial example of what we do with messaging but you get the idea, User A does something User B needs to knows about it. 这是我们如何处理消息的一个简单例子,但是您知道了,用户A做了用户B需要了解的事情。

I have implemented a system using Jabber-net for C# and an OpenFire Jabber Server. 我已经实现了使用C#的Jabber-net和OpenFire Jabber服务器的系统。 Basically when a message is to be sent, a new row gets inserted on a messages table in the database. 基本上,当要发送消息时,将在数据库的消息表中插入新行。 The messages table is watched by a service client using the SqlDependancy object, so that when a new message is ready the service builds the relevant message and sends it to the desired client via Jabber and the OpenFire server. 服务客户端使用SqlDependancy对象监视messages表,以便在准备好新消息时,服务将构建相关消息并将其通过Jabber和OpenFire服务器发送到所需的客户端。

This works OK, however OpenFire's out of the box functionality is for supporting Instant Messaging which obviously isn't what I'm trying to achieve . 这行得通,但是OpenFire的开箱即用功能是为了支持即时消息传递,这显然不是我要实现的目标。 The problem I have is that if a user is logged in to two Application Contexts (ie Test and Live) OpenFire does not know which one to send a message to because the JID structure of user@server/resource takes no notice of the resource. 我的问题是,如果用户登录到两个应用程序上下文(即“测试”和“实时”),则OpenFire不知道将消息发送到哪个应用程序上下文,因为user @ server / resource的JID结构不会注意到该资源。

Basically the way I'm currently using OpenFire and Jabber-net isn't quite right. 基本上,我目前使用OpenFire和Jabber-net的方式不太正确。

Is there a pattern I can use for achieving what I want to achieve ie send a message to a client telling it do something, whilst being able to specify which client you are sending the message too. 有没有一种模式可以用来实现我想要实现的目标,即向客户端发送一条消息,告诉它执行某项操作,同时还可以指定要向哪个客户端发送消息。 XMPP seemed like the answer because I can construct my own messages types to be parsed. XMPP似乎是答案,因为我可以构造自己的要解析的消息类型。

My application is a Windows Forms, .NET 3.5 C# application. 我的应用程序是Windows Forms .NET 3.5 C#应用程序。

我只是添加一些数据来指示受影响的应用程序上下文,并让其他客户端决定是否需要处理消息。

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

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