- 浏览: 19511 次
- 性别:
- 来自: 苏州
最新评论
在网上找了许多的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"); } */ ]]--> RemoteObject id="server" destination="serverpushserver" result="remoteServerCallback(event)"/>
发表评论
-
java截取字符串
2012-07-06 09:51 685★☆★☆★☆★☆★☆★☆ 夫子是神圣的而我是荒诞的 ... -
正则表达式 - 自动生成器
2012-07-06 09:45 1033正则表达式的强大众所周知,它令程序员的头痛程度也数一数二的 ... -
常用的正则表达式
2012-07-06 09:37 623常用表达式: "^\d+$" // ... -
用VC把 图片做成独立的 DLL的两种方法
2012-07-06 09:30 817用VC把 图片做成独 ... -
Ajax 联动
2012-07-05 20:44 578$(document).ready( fun ... -
组件、控件和插件的区别
2012-07-03 13:42 610组件、控件和插件 ... -
组件、控件和插件的区别
2012-07-03 12:19 940组件、控件和插件 ... -
flex datagird渲染图片和按钮
2012-07-02 10:15 587用户操作 [留言] [发消息] [加为好友] ... -
Flex property style
2012-07-02 10:15 595用户操作 [留言] [发消息] [加为好友] ... -
FLEX文件下载
2012-07-02 10:15 560文件下载没有文件上传那么麻烦,只需从服务器指定的目录获取即 ... -
FLEX 条形图(柱状图)设置刻度为百分比
2012-07-02 10:15 643作者原创,如需转载请注明出处:www.krzone.org ... -
Flex和Spring的整合
2012-07-01 09:37 454关于Flex Adobe Flex是一套创建富客户端应用( ... -
实现FLEX 通过AMF跟PHP通信
2012-07-01 09:37 819AMF flex一种远调用 ... -
Flex编程学习基础
2012-07-01 09:37 672Flex是Adobe公司推出 ... -
Flex + LCDS + Java 入门教程
2012-07-01 09:37 468一.引 很多 ... -
关于vs2005的“应用程序配置不正确,无法运行”问题的解决方法
2012-06-30 17:53 622关于vs2005的"应 ... -
无输入法的解决方法
2012-06-30 17:53 5411、一般来说,我们 ... -
WordPress初级教程-20: 忘记Wordpress密码的5种解决方法
2012-06-30 17:53 804来源于 WordPress初级教程-20: 忘记Wordp ... -
TC2.0 在winxp下initgraph崩溃原因以及解决方法
2012-06-30 17:53 822用rectangle()函数。 你得 ...
相关推荐
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 用于推送案例,适合没有这方面知识的初学者参考。