flex有两种传输模式 request-response模式和producer-consumer模式。http,webservice,rpc采用前者,消息采用后者。
《blazeDS Developer Guide》中给出了例子,我稍加改造,做了个聊天室。测试显示,这种方式的速度不容乐观。没有加缓冲池,不知道加了会不会能有改善。
chatTest.html代码:
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
creationComplete="logon();" height="432" width="686" borderColor="#141616">
<mx:Script>
<![CDATA[
import mx.messaging.messages.*;
import mx.messaging.events.*;
private function logon():void {
consumer.subscribe();
}
private var begintime:Date;
private var endtime:Date;
private function messageHandler(event: MessageEvent):void {
ta.text += event.message.body;
endtime=new Date();
var elapse:Number=endtime.valueOf()-begintime.valueOf();
ta.text+=" --耗时:"+elapse+" 毫秒" + "\n";
}
private function sendMessage():void {
var message: AsyncMessage = new AsyncMessage();
message.body = userName.text + ": " + msg.text;
producer.send(message);
msg.text = "";
begintime=new Date();
}
]]>
</mx:Script>
<mx:Producer id="producer" destination="marschat"/>
<mx:Consumer id="consumer" destination="marschat" message="messageHandler(event)"/>
<mx:TextArea id="ta" width="640" height="231" x="13.5" y="37" fontSize="12" fontFamily="Times New Roman" color="#DF1500"/>
<mx:TextInput id="userName" x="100" y="275" width="200" fontWeight="bold" text="Eric Han"/>
<mx:Label text="UserName" x="10" y="275" width="80" color="#EEF5F6" fontWeight="bold"/>
<mx:Label text="message" x="10" y="320" width="80" color="#EEF5F6" fontWeight="bold"/>
<mx:TextInput id="msg" width="546" x="98" y="318" />
<mx:Button label="Send" click="sendMessage();" x="318.5" y="377"/>
</mx:Application>
messaging-config.xml配置文件加入:
<destination id="marschat" channels="my-polling-amf" />
启动服务器(我的是tomcat),输入地址:http://localhost:8888/GoNow/chatTest.html

分享到:
相关推荐
示例代码中使用的`mx:Application`、`mx:Script`、`mx:Producer`、`mx:Consumer`等都是Flex MX组件,它们是Adobe Flex框架的一部分,用于构建富互联网应用程序(RIA)。 通过以上知识点,我们可以理解Flex如何实现...
"flex的xiff访问openfire服务器的demo"是一个示例项目,展示了如何使用Flex和XIFF库连接到Openfire服务器并进行基本的聊天功能。通过这个示例,开发者可以学习以下关键知识点: 1. **Flex环境搭建**:首先需要安装...
这通常涉及到使用`MessageBroker`类,`Service`和`Destination`配置,以及`Producer`和`Consumer`对象。 7. **安全性与性能优化**: 在生产环境中,考虑安全因素,你可能需要对JMS连接进行认证和授权,同时对消息...
1. **客户端程序**:通常是一个基于Flex或AIR的应用程序,这些应用通过特定的Flex组件(如`RemoteObject`, `HTTPService`, `WebService`, `Producer` 和 `Consumer`)与BlazeDS服务器通信。除了Flex或AIR之外,也...
在Flex消息服务中,发送消息的应用被称为生产者(producer),而接收消息的应用被称为消费者(consumer)。 消息接收点(message destination)是负责数据转换为消息,以及将消息转换为消费者可以使用的数据格式的...
- **Producer和Consumer组件组合使用**:演示如何在一个应用程序中同时使用Producer和Consumer组件。 - **消息过滤**:介绍如何根据条件过滤消息。 - **消息服务配置**:指导如何配置消息服务以满足不同的需求。 ##...
Flex+SSH框架是指Flex前端与Spring、Struts、Hibernate组成的后端技术栈相结合的一种架构模式。在该模式下,Flex应用程序通过BlazeDS与Java服务器端进行通信。 搭建Flex+SSH框架的具体步骤包括: 1. **安装Flex...
**客户端程序** 通常是使用 **Flex** 或 **AIR** 编写的,这些客户端程序利用 **Flex SDK** 中提供的组件(如 **RemoteObject**、**HTTPService**、**WebService**、**Producer** 和 **Consumer**)与 **BlazeDS** ...