C# 客户端到客户端消息传递
我将尝试首先准确解释我想要实现的目标。
假设两个用户正在使用 Windows 窗体应用程序,当用户 A 打开特定窗体时,将向该窗体底层的数据记录应用锁定,以便当时只有该用户可以进行更改。
用户 B 有一个所有记录的列表(在网格中),其中包含对用户 A 已打开的记录的引用。我们想要做的是,当用户 A 打开记录时,用户 B 的记录列表会更新以显示该行旁边的锁定图标指示该记录正在使用中。
这是我们如何处理消息传递的一个简单示例,但您明白了,用户 A 做了一些用户 B 需要了解的事情。
我已经使用 C# 的 Jabber-net 和 OpenFire Jabber 服务器实现了一个系统。 基本上,当要发送消息时,会在数据库的消息表中插入一个新行。 服务客户端使用 SqlDependancy 对象监视消息表,以便当新消息准备好时,服务构建相关消息并通过 Jabber 和 OpenFire 服务器将其发送到所需的客户端。
这工作正常,但是 OpenFire 的开箱即用功能是用于支持即时消息传递,这显然不是我想要实现的。 我遇到的问题是,如果用户登录到两个应用程序上下文(即测试和实时),OpenFire 不知道向哪一个发送消息,因为 user@server/resource 的 JID 结构不会注意到该资源。
基本上我目前使用 OpenFire 和 Jabber-net 的方式不太正确。
是否有一种模式可以用来实现我想要实现的目标,即向客户端发送一条消息,告诉它做某事,同时能够指定您要发送消息的客户端。 XMPP 似乎是答案,因为我可以构建自己的要解析的消息类型。
我的应用程序是 Windows 窗体、.NET 3.5 C# 应用程序。
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.
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.
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.
I have implemented a system using Jabber-net for C# and an OpenFire Jabber Server. 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.
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 . The problem I have is that if a user is logged in to two Application Contexts (i.e. 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.
Basically the way I'm currently using OpenFire and Jabber-net isn't quite right.
Is there a pattern I can use for achieving what I want to achieve i.e. 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.
My application is a Windows Forms, .NET 3.5 C# application.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我只需添加更多数据来指示哪个应用程序上下文受到影响,并让其他客户端决定是否需要处理该消息。
I'd just add some more data to indicate which Application Context is affected and have the other clients decide whether they need to handle the message or not.