The example reviewed below demonstrates data push from a server-side Java application to three different native mobile app implementations: iOS, Android and Windows Phone. The server updates the data every 1.5 seconds and delivers it to the clients. The iOS client uses a persistent RTMP connection, the Android and Windows Phone clients use publish/subscribe messaging (via polling) to receive server-side updates. The source code for each mobile implementation and the server-side project (with deployment instructions) is available below the video:
Download source code:
Server-side Compilation and Deployment instructions:
- Download and install WebORB for Java (make sure to download version 4.3 or above) .The product is available for free with the Community Edition license. Without a license key, it will work in the “development mode” which will be sufficient to the this example. See WebORB Licensing for additional details.
- Download Java project files.
- To compile the Java project, add the following JAR dependencies: weborb.jar, red5.jar, spring-core-3.0.0.jar. All the required jar files can be found in [WEBORB-INSTALL-DIR]/webapp/WEB-INF/lib.
- The compiled classes can be deployed to [WEBORB-INSTALL-DIR]/webapp/WEB-INF/classes/examples/weborb (if the package structure changes, the directories under WEB-INF/classes will have to change as well).
- Register new messaging destinations. To do this, open [WEBORB-INSTALL-DIR]/webapp/WEB-INF/flex/messaging-config.xml in a text editor, add the following destination declaration before the closing </service> element, then save the file:
<destination id="StockExchangeDestination"> <properties> <server> <durable>false</durable> </server> <message-storage-policy>weborb.messaging.v3.MemoryStoragePolicy</message-storage-policy> <message-service-handler>weborb.messaging.v3.MessagingServiceHandler</message-service-handler> </properties> <channels> <channel ref="my-polling-amf"/> </channels> </destination>
- Register new RTMP messaging application: To do this create a new XML file with the following contents in [WEBORB-INSTALL-DIR]/webapp/WEB-INF/classes. Name the file stockexchange-web.xml (alternatively, you can download the file from here):
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean id="stockexchange.context" class="org.red5.server.Context" autowire="byType" /> <bean id="stockexchange.scope" class="org.red5.server.WebScope" init-method="register"> <property name="server" ref="red5.server" /> <property name="parent" ref="global.scope" /> <property name="context" ref="stockexchange.context" /> <property name="handler" ref="stockexchange.handler" /> <property name="contextPath" value="/StockExchange" /> <property name="virtualHosts" value="*,localhost, localhost:1935, localhost:8080, 127.0.0.1:8080" /> </bean> <bean id="stockexchange.handler" class="examples.weborb.AppAdapter" singleton="true" /> </beans>
- Modify beanRefContect.xml from [WEBORB-INSTALL-DIR]/webapp/WEB-INF/classes by adding the following XML element before the closing </list> element.
<value>stockexchange-web.xml</value>
- Run WebORB for Java in a command prompt/terminal window by using the following command (run the command from the WebORB installation directory):
java -jar weborb.jar - Verify that WebORB is running by opening the management console from: http://localhost:8080
- Compile and run the mobile applications. Use the following configuration parameters:
iOS – Hostname: if launching in iOS Simulator, use localhost, otherwise enter IP address of the machine where weborb is running. Application name: StockExchange, port – 1935
Android and Windows Phone- WebORB URL – http://localhost:8080/weborb.wo (if running on a device, substitute localhost with the IP address of the machine where WebORB is running).
Enjoy!