Java Server Push To Flex (ServerPush)
- 博客分类:
- 技术杂绘
Java Server Push To Flex (ServerPush)
2010年06月14日
在网上找了许多的Flex与java 通信做ServerPush 的例子,发现有许多不正确,今天就做了一小程序。希望对大家有用
1. Product 类 package com.east.flex.serverpush.entity; /** * 产品类 * @author East(张栋芳) * * 2010-6-12 */ public class Product { private String month; private int profit; private int expenses; private int amount; public String getMonth() { return month; } public void setMonth(String month) { this.month = month; } public int getProfit() { return profit; } public void setProfit(int profit) { this.profit = profit; } public int getExpenses() { return expenses; } public void setExpenses(int expenses) { this.expenses = expenses; } public int getAmount() { return amount; } public void setAmount(int amount) { this.amount = amount; } } 2. ServerPushThread package com.east.flex.serverpush.chart; import java.util.ArrayList; import java.util.List; import java.util.Random; import com.east.flex.serverpush.entity.Product; import flex.messaging.MessageBroker; import flex.messaging.messages.AsyncMessage; import flex.messaging.util.UUIDUtils; /** * 构造数据后台线程 * * @author East(张栋芳) * * 2010-6-13 */ public class ServerPushThread extends Thread { public boolean running = true; @Override public void run() { MessageBroker msgBroker = MessageBroker.getMessageBroker(null); String clientId = UUIDUtils.createUUID(); while (running) { /* ============================== */ // TODO do someing /* ============================== */ List productList = getProductList(); AsyncMessage msg = new AsyncMessage(); msg.setDestination("serverpush"); msg.setClientId(clientId); msg.setMessageId(UUIDUtils.createUUID()); msg.setTimestamp(System.currentTimeMillis()); /* 设置消息信息,发布到客户端去 */ msg.setBody(productList); msgBroker.routeMessageToService(msg, null); try { Thread.sleep(10000); } catch (InterruptedException se) { } } } /** * 模拟数据信息 * * @return */ public List getProductList() { List productList = new ArrayList(); for (int i = 1; i --> 5. remoting-config.xml com.east.flex.serverpush.CreateProduct com.east.flex.serverpush.chart.ServerPushServer 6. Product.as package com.east.flex.entity { import mx.rpc.remoting.RemoteObject; [RemoteClass(alias="com.east.flex.serverpush.entit y.Product")] public class Product { public var month:String; public var profit:int; public var expenses:int; public var amount:int; public function Product() { } } } 7.ServerPushChart.mxml import com.east.flex.entity.Product Flex Server Push 功能*/ import mx.messaging.messages.IMessage; import mx.messaging.events.MessageEvent; import mx.utils.ArrayUtil; import mx.rpc.events.ResultEvent; import mx.collections.ArrayCollection; import mx.controls.Alert; import mx.messaging.ChannelSet; import mx.messaging.Consumer; [Bindable] private var p:Product; private var array:ArrayUtil; [Bindable] private var expensesAC:ArrayCollection = null; public var consumer2:Consumer = null; public function messageHandler(event:MessageEvent):void { linechart.dataProvider = event.message.body; trace("server push data to client.............."); } public function remoteServerCallback(event:ResultEvent):void { trace("Server is start...."); //Alert.show("Server is start....."+event.message); } public function startServer(event:MouseEvent):void { server.start(); } public function stopServer(event:MouseEvent):void { server.stop(); } /* public function submsg():void { Alert.show("click start"); consumer= new Consumer(); consumer.destination = "serverpush"; consumer.subtopic = "tick"; consumer.channelSet = new ChannelSet(["my-streaming-amf"]); consumer.addEventListener(MessageEvent.MESSAGE, messageHandler); consumer.subscribe(); Alert.show("click end"); } */ ]]-->
发表评论
-
Flex 文件上传导入组件
2012-01-20 01:22 872Flex 文件上传导入组件 2010年09月13日 上文 ... -
FLEX 开发领域你知多少?
2012-01-20 01:22 529FLEX 开发领域你知多少? ... -
Flex通过javascript读写cookie
2012-01-20 01:22 689Flex通过javascript读写cookie 2010年 ... -
全面认识Flex弹出窗口用法
2012-01-20 01:22 672全面认识Flex弹出窗口用 ... -
很久很久以前的事
2012-01-19 09:12 677很久很久以前的事 2010年08月01日 今天给自己的大 ... -
2011-9-15
2012-01-19 09:12 4742011-9-15 2011年09月15日 第 1课时 ... -
如何培养一年级学生良好的学习习惯
2012-01-19 09:12 273如何培养一年级学生良好的学习习惯 2011年06月28日 ... -
各位家长非常辛苦,其他老师也很辛苦,孩子也很辛苦。希望我们相互理解,用朋友的角度去商量让孩子变的好起来
2012-01-19 09:12 537各位家长非常辛苦,其他 ... -
日记那点破事儿
2012-01-19 09:12 335日记那点破事儿 2011年0 ... -
JavaSE常见面试题(一)
2012-01-17 01:41 441JavaSE常见面试题(一) 201 ... -
windows中apache2配置性能优化以及测试小结
2012-01-17 01:41 469windows中apache2配置性能优化以及测试小结 20 ... -
。Net面试题(一)
2012-01-17 01:41 675。Net面试题(一) 2011年10月17日 .net面 ... -
VB.net多线程入门
2012-01-17 01:41 927VB.net多线程入门 2011年06月03日 出处 ... -
NIO
2012-01-17 01:41 952NIO 2011年07月27日 1 ... -
meego开发的学习路线
2012-01-15 20:56 535meego开发的学习路线 2011年06月26日 不同版 ... -
memmem 函数
2012-01-15 20:56 735memmem 函数 2011年06月02日 软件研发的面 ... -
文件读写函数的使用方法
2012-01-15 20:56 634文件读写函数的使用方法 2010年04月11日 原文地址 ... -
宝供实习
2012-01-15 20:55 538宝供实习 2010年04月04日 响宝供实习已经有 ... -
C库函数
2012-01-15 20:55 627C库函数 2010年06月28日 rename()文件改 ...
相关推荐
NULL 博文链接:https://dojava.iteye.com/blog/1711575
java中的Servlet实现Server_Push技术的聊天室!
java server push
ASP.NET(C#) ServerPush
基于dwr的server push ,后台是java,往页面推送数据
java-Push开源实时消息推送系统
JavaPush消息推送
asp.net server push 长连接asp.net server push 长连接已调试成功
以告警数据为例,告警数据通过mq、socket等方式进入系统,在java服务器通过监听来监听消息队列数据,接收后推送到flex各个客户端。blazeDS采用amf协议。该协议可以传输Object, Array, Date, XML。由于AMF采用二进制...
.net实现Server Push(服务器推送)源码
NULL 博文链接:https://fanfq.iteye.com/blog/1405385
Server Push入门介绍,讲术服务器推送的原理及过程
javapush消息推送
NULL 博文链接:https://packecho.iteye.com/blog/857027
一个dwr server push 做的web room ,使用服务器推技术,实现点对点聊天...
dwr serverpush chat room 点对点聊天 ==========================
asp.net server push 长连接 源码 示例 测试通过.一看就明白,
java-push-demo 用于推送案例,适合没有这方面知识的初学者参考。