C#客户端到客户端消息传递 [英] C# Client to Client Messaging

查看:206
本文介绍了C#客户端到客户端消息传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将尽力解释我首先要实现的目标.

I will try and explain exactly what I want to achieve first.

想象有两个用户正在使用Windows窗体应用程序,当用户A打开一个特定的窗体时,会将锁应用于该窗体下的数据记录,以便当时只有该用户可以进行更改.

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.

用户B具有所有记录的列表(在网格中),其中包括对用户A已打开的记录的引用.我们要做的是在用户A打开记录时更新用户B的记录列表在该行旁边显示一个锁定图标,以指示该记录正在使用中.

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.

这是我们处理消息传递的一个简单例子,但是您知道了,用户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.

我已经使用C#和OpenFire Jabber服务器的Jabber-net实现了一个系统.基本上,当要发送消息时,将在数据库的消息表中插入新行.服务客户端使用SqlDependancy对象监视messages表,以便在准备好新消息时,服务会构建相关消息,并通过Jabber和OpenFire服务器将其发送到所需的客户端.

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.

这可以正常工作,但是OpenFire的开箱即用功能是为了支持即时消息传递,这显然不是我要实现的目标.我遇到的问题是,如果用户登录到两个应用程序上下文(即测试和实时),则OpenFire不知道将消息发送给哪个应用程序上下文,因为user @ server/resource的JID结构不会注意到该资源.

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.

基本上,我目前使用OpenFire和Jabber-net的方式不太正确.

Basically the way I'm currently using OpenFire and Jabber-net isn't quite right.

是否有一种模式可以用来实现我想要实现的目标,即向客户端发送一条消息,告诉它执行某项操作,同时还可以指定您也向哪个客户端发送消息. XMPP似乎是答案,因为我可以构造自己的要解析的消息类型.

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.

我的应用程序是Windows Forms .NET 3.5 C#应用程序.

My application is a Windows Forms, .NET 3.5 C# application.

推荐答案

我将添加更多数据以指示受影响的应用程序上下文,并让其他客户端决定是否需要处理消息.

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.

这篇关于C#客户端到客户端消息传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆