锐英源软件
第一信赖

精通

英语

开源

擅长

开发

培训

胸怀四海 

第一信赖

当前位置:锐英源 / 英语翻译 / 基于Workflow Foundation的简单XMPP客户端
服务方向
人工智能数据处理
人工智能培训
kaldi数据准备
小语种语音识别
语音识别标注
语音识别系统
语音识别转文字
kaldi开发技术服务
软件开发
运动控制卡上位机
机械加工软件
软件开发培训
Java 安卓移动开发
VC++
C#软件
汇编和破解
驱动开发
联系方式
固话:0371-63888850
手机:138-0381-0136
Q Q:396806883
微信:ryysoft

锐英源精品开源心得,转载请注明:“锐英源www.wisestudy.cn,孙老师作品,电话13803810136。”需要全文内容也请联系孙老师。


基于Workflow Foundation的简单XMPP客户端


Introduction

The article describes a simple XMPP client application based on the Windows Workflow Foundation, which allows to send and receive messages and also to add and remove contacts from your contact list.

介绍

本文介绍了一个基于Windows Workflow Foundation的简单XMPP客户端应用程序,它允许发送和接收消息,还可以添加和删除联系人列表中的联系人。

 

Background

Extensible Messaging and Presence Protocol

The Extensible Messaging and Presence Protocol (XMPP) is an open technology for real time communication, using Extensible Markup Language (XML) as the base format for exchanging information. In essence, XMPP provides a way to send small pieces of XML from one entity to another in close to real time.

The XMPP protocol is taken as the RFC standard, and is described by the following documents:

  • RFC 3920 Extensible Messaging and Presence Protocol: Core
  • RFC 3921 Extensible Messaging and Presence Protocol: Instant Messaging and Presence
  • 背景

    可扩展的消息传递和在线协议

    可扩展消息和存在协议(XMPP)是一种用于实时通信的开放技术,使用可扩展标记语言(XML)作为交换信息的基本格式。本质上,XMPP提供了一种近乎实时地将小块XML从一个实体发送到另一个实体的方法。

    XMPP协议被视为RFC标准,并由以下文档描述:

    • RFC 3920可扩展消息传递和在线协议:核心
    • RFC 3921可扩展消息传递和在线协议:即时消息和在线状态

Windows Workflow Foundation

Windows Workflow Foundation (WF) is a Microsoft technology for defining, executing, and managing workflows. This technology was first released in November 2006 as a part of .NET Framework 3.0.

WF is a special runtime environment that manages the execution of programs that are composed of resumable program statements. In WF, a resumable program statement is called an Activity. A resumable program is a composition of activities. In WF, such a program is often called a Workflow.

Windows Workflow Foundation

Windows Workflow Foundation(WF)是一种用于定义,执行和管理工作流的Microsoft技术。该技术于2006年11月作为.NET Framework 3.0的一部分首次发布。

WF是一个特殊的运行时环境,用于管理由可恢复的程序语句组成的程序的执行。在WF中,可恢复的程序语句称为活动。可恢复的程序是活动的组合。在WF中,这样的程序通常称为工作流程

 

Using the Code

The project consists of two libraries and an XOML-file: JabberClient.dll (root namespace is Jabber.Client), WorkflowActivities.dll (root namespace is Workflow), and Sequence.xml.该项目由两个库和一个XOML文件组成:JabberClient.dll(根名称空间为Jabber.Client),WorkflowActivities.dll(根名称空间为Workflow)和Sequence.xml

Namespace Jabber.Client

The Jabber.Client namespace includes the types for the XMPP client realization with minimal functionality, which are presented in the following list:

  • Jabber.Client.Core.TcpBinder wraps the standard System.Net.Sockets.Socket class.
  • Jabber.Client.Core.ClientState enumerates the possible client states.
  • Jabber.Client.Xml.PacketBuilder contains the methods for building XML-strings for XMPP-server requests (authentication, contact list request, message sending, etc.).
  • Jabber.Client.Xml.PacketParser contains the methods for XMPP-server response parsing.
  • Jabber.Client.Cryptography.DigestMD5Auth implies digest authentication according to RFC2831.
  • Jabber.Client.JabberClient encapsulates all of XMPP-client logic.
  • 命名空间Jabber.Client

    该Jabber.Client命名空间包含类型的XMPP客户端实现以最小的功能,这在下面的列表中提出:

    • Jabber.Client.Core.TcpBinder包装标准System.Net.Sockets.Socket类。
    • Jabber.Client.Core.ClientState 枚举可能的客户端状态。
    • Jabber.Client.Xml.PacketBuilder 包含为XMPP服务器请求构建XML字符串的方法(身份验证,联系人列表请求,消息发送等)。
    • Jabber.Client.Xml.PacketParser 包含XMPP服务器响应解析的方法。
    • Jabber.Client.Cryptography.DigestMD5Auth 根据RFC2831暗示摘要认证。
    • Jabber.Client.JabberClient 封装了所有XMPP客户端逻辑。

Namespace Worflow

The Worflow namespace includes the set of activities and helper classes which help to specify the program algorithm. You can see the list of main activities below.

  • Workflow.Activities.Receiver retrieves the message from a Queue, converts it with the help of the ReceiveMethod method of the ReceiveType class of the AssemblyFile assembly, and calls the OnReceived method of the IWorkflowDataService interface.
  • Workflow.Activities.Sender retrieves the message from a Queue, converts it with the help of the SendMethod method of the SendType class of the AssemblyFile assembly, and calls the Send method of the IWorkflowDataService interface.
  • Workflow.Activities.StateSendAndReceive sends the message and receives the response. For it to work, the activity needs these properties: ReceiveMethod, ReceiveType, AssemblyFile, SendMethod, SendType, and Context. The Context property is used as in-out params.
  • Workflow.Activities.Sequence is a type of CompositeActivity, which sequentially executes its child activities.
  • Workflow.Activities.Switch emulates a switch instruction.

Thus, the simple XMPP client's XOML-file is represented below:

命名空间Worflow

该Worflow命名空间包括一系列活动和辅助类,这有助于指定程序算法。您可以在下面看到主要活动列表。

  • Workflow.Activities.Receiver从a中检索消息,在程序集类Queue的ReceiveMethod方法的帮助下转换它,并调用接口的方法。ReceiveTypeAssemblyFileOnReceivedIWorkflowDataService
  • Workflow.Activities.Sender从队列中检索消息,在AssemblyFile程序集SendType类的SendMethod方法的帮助下转换它,并调用IWorkflowDataService接口的Send方法。
  • Workflow.Activities.StateSendAndReceive发送消息并接收响应。对于它的工作,活动需要这些特性:ReceiveMethod, ReceiveType,AssemblyFile,SendMethod,SendType,和Context。该Context属性用作进出的参数。
  • Workflow.Activities.Sequence是一种类型CompositeActivity,它顺序执行其子活动。
  • Workflow.Activities.Switch模仿switch指令。

因此,简单的XMPP客户端的XOML文件如下所示:

 

<Sequence x:Name="root"

xmlns="http://Workflow/Activities"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:wf="http://schemas.microsoft.com/winfx/2006/xaml/workflow">
<Switch x:Name="sw1">
<StateSequence x:Name="Auth" Queue="AuthInputQueue">
<StateSendAndReceive Name="step1_0" AssemblyFile="JabberClient.dll"

SendType="Jabber.Client.Xml.PacketBuilder" SendMethod="AuthStreamHeader"

ReceiveType="Jabber.Client.Xml.PacketParser" ReceiveMethod="AuthStreamHeader1"

Context="{wf:ActivityBind Auth, Path=Context}" />
<StateSendAndReceive Name="step1_1" AssemblyFile="JabberClient.dll"

ReceiveType="Jabber.Client.Xml.PacketParser"

ReceiveMethod="AuthStreamHeader2"

Context="{wf:ActivityBind step1_0, Path=Context}" />
........
</StateSequence>
<Receiver x:Name="Receive" Queue="ReceiveQueue"

AssemblyFile="JabberClient.dll"

ReceiveType="Jabber.Client.Xml.PacketParser"

ReceiveMethod="ResponseMessage" />
<Sender x:Name="Send" Queue="SendQueue"

AssemblyFile="JabberClient.dll"

SendType="Jabber.Client.Xml.PacketBuilder"

SendMethod="ChatMessage"/>
<Sender x:Name="Status" Queue="StatusQueue"

AssemblyFile="JabberClient.dll"

SendType="Jabber.Client.Xml.PacketBuilder"

SendMethod="PresenceShow"/>
<Sender x:Name="Roster" Queue="RosterQueue"

AssemblyFile="JabberClient.dll"

SendType="Jabber.Client.Xml.PacketBuilder"

SendMethod="Roster"/>
<Sender x:Name="Subscribe" Queue="RosterQueue"

AssemblyFile="JabberClient.dll"

SendType="Jabber.Client.Xml.PacketBuilder"

SendMethod="Subscribe"/>
<Sender x:Name="Unsubscribe" Queue="RosterQueue"

AssemblyFile="JabberClient.dll"

SendType="Jabber.Client.Xml.PacketBuilder"

SendMethod="Unsubscribe"/>
</Switch>
</Sequence>

It follows from the XOML-file that the StateSequence activity performs the client authentication on the XMPP-server according to RFC2831. Dynamic binding of the Context property is used in child Activities.

An example of using a simple XMPP-client is shown below:

从XOML文件开始,StateSequence活动根据RFC2831在XMPP服务器上执行客户端身份验证。动态绑定Context属性用于子活动。

使用简单XMPP客户端的示例如下所示:

....
using Jabber.Client;
using Jabber.Client.Core;
....

using (JabberClient jabber =
new JabberClient("jabber.org", "vba32cc", "1234qwer"))
{
//subscribe to events
jabber.Authentificated += new EventHandler(jabber_Authentificated);
jabber.RosterReceived += new RosterHandler(jabber_RosterReceived);
jabber.MessageReceived += new MessageHandler(jabber_MessageReceived);

Console.WriteLine("Authentification...");
jabber.Auth();
string s = Console.ReadLine();
Console.WriteLine("Client state={0}", jabber.State);
while (!string.IsNullOrEmpty(s))
{
if (jabber.State == ClientState.Authentificated)
{
Contact contact = new Contact("", "veleslaff@jabber.ru");
jabber.AddToContacts(contact); //Add to contacts
jabber.SetStatusForContact(contact, UserStatus.Online);//Set status
jabber.Send(contact, s); //Send message
jabber.Contacts(); //Get roster list
}
s = Console.ReadLine();
}
}
....

友情链接
版权所有 Copyright(c)2004-2021 锐英源软件
公司注册号:410105000449586 豫ICP备08007559号 最佳分辨率 1024*768
地址:郑州大学北校区院(文化路97号院)内