Categories

  • An excellent post on delivering real-time updates from .NET to JavaScript via WebSockets by using WebORB for .NET: http://t.co/8ONjyw59
  • We're working on some cool samples demonstrating Sencha component integration with WebORB's websockets and data management. Stay tuned.
  • For all Flexers out there, check out the following blog post, looks like a problem in ArrayCollection serialization: http://t.co/qbZuTEhy
  • none - intentionally blocks websocket handshake responses. Not only they do not support it, they do not allow others either

Archives

Data Paging for Flex - Efficient Server-Side Data Retrieval

Loading too much data into a Flex application can easily present a problem. Flex data components like lists or datagrids do not deal with very large data providers very well. Additionally, fetching a lot of data from the server may have a significant impact on the application’s performance as the client-side memory footprint of the application can grow to be quite large. A common solution for these problems is data paging. The entire dataset is split into blocks (pages) and a page of data is loaded on  the as-needed basis (for example, when the application user tries to scroll through the data in a datagrid).

To simplify this task for Flex developers, we introduced an API and a Flex data component which makes it possible to dynamically fetch data from Java. .NET or PHP services. The component can be used as a data provider for any Flex data-bound UI component. Additionally, we implemented a very powerful memory management system which makes sure that only specified number of pages is kept in memory. That way, you can easily visualize a data set with millions of records in a single data grid without loading all the records into memory.

The video below reviews an example illustrating the usage of the APIs. The example is also available live at the URL below:
http://examples.themidnightcoders.com/blog/findharley/FindHarleyWeb.html

The source code for the example and the sample database is available at the bottom of this post. Enjoy!

Source code and Database resources:

Deployment instructions:

  1. Download and install WebORB for Java.
  2. Create ‘findharley’ database schema (database) and restore the database by using the SQL script. The server side code uses the root/sa userid and password. You can grant access permissions for the database to another user and modify the Java code to use different credentials.
  3. Compile the server-side code. Make sure to update the JDBC connection string with the updated userid and password – line 221 in FHService.java (see the item above).
  4. The compiled server-side code can be deployed as .class files into WebORB’s WEB-INF/classes folder or as a jar file into WEB-INF/lib
  5. Open the client-side project in Flash Builder, adjust the server-side path, the path to weborb-services-config.xml for the -services compiler argument and Flash Build Path.
  6. Obtain a Google Maps API key from the following page: http://code.google.com/apis/maps/signup.html
  7. Replace the following string PUT-YOUR-GOOGLE-MAPS-API-KEY-HERE in src/FindHarleyWeb.mxml with your Google Maps API key.

Integrating Native Android with .NET via Publish/Subscribe API

A few days ago we published an example demonstrating .NET data push to a native iPhone application. In that example the backend service was a .NET application hosted in WebORB for .NET. The application used WebORB as an RTMP server to deliver real-time updates to the client devices. In addition to the RTMP clients (like an iOS devices or Flex apps), a slightly modified version of the same code can easily support clients connecting via publish/subscribe API. An example of a such client can be a native Android application using our client-side library. We put together a native Android application and extended the server-side code to support publish/subscribe clients. The video below demonstrates the example in action and provides a brief code review. The instructions for setting up and running the example follow the video.

Follow the steps below to deploy and run the example:

  1. Download and install the latest version of WebORB for .NET. (This post assumes the product is installed in the default installation directory. For the version 4.4, the installation directory is: c:/Program Files/WebORB for .NET/4.4.0.0/)
  2. Download the client-side project from:
    http://examples.themidnightcoders.com/blog/StockExchangeAndroidClient.zip
  3. Download the server-side project from:
    http://examples.themidnightcoders.com/blog/StockExchangeWithPubSub-server.zip
  4. Open the server-side project in Visual Studio. Compile the project and make sure the compiled assembly is copied into the /bin folder in the WebORB installation directory (c:/Program Files/WebORB for .NET/4.4.0.0/bin)
  5. Open messaging-config.xml from c:/Program Files/WebORB for .NET/4.4.0.0/WEB-INF/flex in a text editor.
  6. Add the following XML block before the closing </service> tag:
      <destination id="StockExchangeDestination">
        <properties>
          <server>
            <durable>false</durable>
          </server>
          <message-service-handler>Weborb.Messaging.PubSub.Memory.MessagingServiceHandler</message-service-handler>
          <message-storage-policy>Weborb.Messaging.PubSub.Memory.MemoryStoragePolicy</message-storage-policy>
        </properties>
        <channels>
          <channel ref="my-polling-amf" />
        </channels>
      </destination>
    
  7. Create “StockExchange” directory under the “Applications” folder located at: c:/Program Files/WebORB for .NET/4.4.0.0/Applications)
  8. Create the app.config file in the StockExchange directory with the following contents:
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
    <application-handler>StockExchange.AppHandler</application-handler>
    </configuration>
    
  9. Compile and run the Android project. Once the client application runs enter the WebORB remoting endpoint URL (for example for the local installation it may be http://localhost/weborb4/weborb.aspx). Click the ‘Connect’ button to establish a connection with the server-side application.

.NET Data Push to iPhone application

One of my most favorite features in the Communication Library for iOS is the support for server-side data push to iOS. We put together an example demonstrating the feature in action where a .NET server pushes real-time updates to an iPhone application. The example is demonstrated and reviewed in the video below. The instructions for running the example and the links for the source code are available below the video in this blog post. Enjoy!

Follow the steps below to deploy and run the example:

  1. Download and install the latest version of WebORB for .NET. (This post assumes the product is installed in the default installation directory. For the version 4.4, the installation directory is: c:/Program Files/WebORB for .NET/4.4.0.0/)
  2. Download the client-side project from:
    http://examples.themidnightcoders.com/blog/StockExchangeClient.zip
    (for additional examples, you can also  download the Communication Library for iOS).
  3. Download the server-side project from:
    http://examples.themidnightcoders.com/blog/StockExchange-server.zip
  4. Open the server-side project in Visual Studio. Compile the project and make sure the compiled assembly is copied into the /bin folder in the WebORB installation directory (c:/Program Files/WebORB for .NET/4.4.0.0/)
  5. Create “StockExchange” directory under the “Applications” folder located at: c:/Program Files/WebORB for .NET/4.4.0.0/Applications)
  6. Create the app.config file in the StockExchange directory with the following contents:
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
    <application-handler>StockExchange.AppHandler</application-handler>
    </configuration>
    
  7. Open the WebORB Management Console. Switch to the ‘Messaging Server’ tab and make sure the StockExchange application is listed under the Applications node in the tree.
  8. Run the iOS client application, enter the hostname for the server where WebORB for .NET is running and click Connect to establish a connection with the server-side application.

Integrating native iOS applications with Flash Media Server

The Communication Library for iOS which we have recently released enables developers to integrate native iPhone and iPad applications with various server-side technologies. Since the library implements the RTMP protocol, it can easily connect the iOS applications with any RTMP-enabled media server. One of the most popular media servers is Adobe Flash Media Server. The video below provides an overview of the integration. Specifically, it demonstrates ability to do invocations of the server-side ActionScript running in FMS from the iOS apps using the library. Additionally, there is an example of the FMS data push implemented as an invocation of the client-side Objective-C functions from the code running in FMS.

In addition to the features reviewed in the video, the same library supports Remote Shared Objects. Currently, the integration enables data messaging, but we’re also working on adding support for video and audio broadcast and server-side recording. This new functionality will enable any iOS application to broadcast or record video stream from the device’s camera and audio from the microphone.

Enjoy!

Follow the steps below to configure your own FMS installation to run the same examples:

  1. Download and install Flash Media Server
  2. Create “CallbackDemo” folder under [FMS-INSTALL]/applications
  3. Download and extract CallbackDemo-servercode.zip into [FMS-INSTALL]/applications/CallbackDemo
  4. Create “MethodInvocation” folder under [FMS-INSTALL]/applications
  5. Download and extract MethodInvocation-servercode.zip into [FMS-INSTALL]/applications/MethodInvocation
  6. Download Communication Library for iOS, extract and the examples and open the examples project in XCode

Flex to .NET Chat Client Using Remote Shared Objects

Integrating .NET applications with other client technologies (or even .NET to .NET) may not seem to be a trivial task. I believe Microsoft has done a great job providing a fairly closed technology stack where things work as long as you stick to Microsoft’s prescription of how to go about solving problems. Take for example the task of creating a multi client messaging system between a .NET application and Flex, AIR, Android or iOS client and you will shortly feel the pain. The real challenge is the .NET messaging framework is not very open to accomodate client applications of other than native .NET or ASP.NET. As a result, you will need a messaging server which will serve the purpose of routing broker and messaging “translator” between heterogeneous client applications.

Earlier this month I wrote about Remote Shared Objects and the benefits the feature provides. Since remote shared objects are no longer a feature exclusive to Flash, Flex and AIR clients I put together a messaging example demonstrating how .NET applications can efficiently communicate with Flex and AIR  (and thus Android,  iOS and Blackberry Playbook). The .NET application is a simple (console-based) chat program which uses remote shared objects to exchange data with a Flex client. The Remote Shared Object API and RTMP connectivity comes with the RTMPClient class available in WebORB for .NET. Here’s the full listing of the C# code with an explanation right after the listing:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using Weborb.Client;
using Weborb.Messaging.Net.RTMP;
using Weborb.Messaging.Api.Service;
using Weborb.Messaging.Api.SO;

namespace WeborbClientTest
{
  class Program : IPendingServiceCallback, ISharedObjectListener
  {
    private ThreadStart threadStart;
    private Thread chatThread;
    private AutoResetEvent rsoIsReady = new AutoResetEvent( false );

    private RTMPClient rtmpClient;
    private IClientSharedObject rso;

    static void Main( string[] args )
    {
      Program chatClient = new Program();
      chatClient.StartChat();
    }

    public void StartChat()
    {
      rtmpClient = new RTMPClient();
      rtmpClient.setServiceProvider( this );

      System.Console.WriteLine( "Connecting to the RTMP server running at localhost:2037" );
      rtmpClient.connect( "localhost", 2037, "Chat", null, this );

      threadStart = new ThreadStart( MainChat );
      chatThread = new Thread( threadStart );
      chatThread.Start();
      chatThread.IsBackground = false;
    }

    public void MainChat()
    {
      rsoIsReady.WaitOne();

      System.Console.WriteLine( "Connecting to the 'ChatSO' remote shared object" );
      rso = rtmpClient.getSharedObject( "ChatSO", false );
      rso.addSharedObjectListener( this );

      while( true )
      {
        System.Console.WriteLine( "Enter a message to put into RSO. Press \"Enter\" to stop the loop:" );
        String messageText = System.Console.ReadLine();

        if( messageText.Equals( "" ) )
          break;

        Hashtable messageObject = new Hashtable();
        messageObject[ "imText" ] = messageText;
        messageObject[ "username" ] = ".NET Client";
        messageObject[ "color" ] = 0;
        messageObject[ "isBold" ] = false;
        messageObject[ "isItalics" ] = false;
        messageObject[ "isUnderline" ] = false;

        rso.setAttribute( "UserMessage", messageObject );
      }
    }

    public void resultReceived( IPendingServiceCall call )
    {
      System.Console.WriteLine( "RTMP client connected" );
      rsoIsReady.Set();
    }

    public void onSharedObjectClear( ISharedObjectBase so )
    {
      System.Console.WriteLine( "EVENT: onSharedObjectClear" );
    }

    public void onSharedObjectConnect( ISharedObjectBase so )
    {
      System.Console.WriteLine( "EVENT: onSharedObjectConnect" );
    }

    public void onSharedObjectDelete( ISharedObjectBase so, string key )
    {
      System.Console.WriteLine( "EVENT: onSharedObjectDelete" );
    }

    public void onSharedObjectDisconnect( ISharedObjectBase so )
    {
      System.Console.WriteLine( "EVENT: onSharedObjectDisconnect" );
    }

    public void onSharedObjectSend( ISharedObjectBase so, string method, IList parms )
    {
      System.Console.WriteLine( "EVENT: onSharedObjectSend" );
    }

    public void onSharedObjectUpdate( ISharedObjectBase so, IDictionary<string, object> values )
    {
      System.Console.WriteLine( "EVENT: onSharedObjectUpdate" );
    }

    public void onSharedObjectUpdate( ISharedObjectBase so, Weborb.Messaging.Api.IAttributeStore values )
    {
      System.Console.WriteLine( "EVENT: onSharedObjectUpdate" );
    }

    public void onSharedObjectUpdate( ISharedObjectBase so, string key, object value )
    {
      System.Console.WriteLine( "EVENT: onSharedObjectUpdate" );

      Hashtable messageData = (Hashtable) value;
      System.Console.WriteLine( "property " + key + ",  imText value " + messageData[ "imText" ] );
    }
  }
}

The StartChat method is where the program connects to the localhost server running on port 2037 (WebORB’s default RTMP port). The “Chat” parameter is the name of the messaging application the client connects to. The main chat logic is in the MainChat method. As you can see from the code the MainChat method is executed by a separate thread. The reason for this is the process of establishing a connection and receiving a notification that the connection has been established (lines 34 and 72) is asynchronous. As a result, a separate thread is required so the main method of the application does not end prematurely.

Inside of the MainChat method, the code uses the getSharedObject method to obtain a reference to the specified remote shared object – ChatSO (line 47). A listener object is added to the remote shared object instance so the application receives all the RSO events, including the one when the RSO is updated (lines 111-117).

You can download the complete project from the following URL: http://examples.themidnightcoders.com/blog/RSOClient.zip

To run the example and experience the feature:

  1. Compile the example code (you might need to set the weborb.dll assembly reference)
  2. Run the WebORB Management Console
  3. Run the .NET application
  4. In the management console switch to the Help/Resources tab, then click the Examples link
  5. In the examples tree in the console navigate to: FLEX Examples > Real-time Messaging (RTMP) > Basic Text Chat
  6. Type in a send messages both in the Flex and .NET clients – both send and receive data

To see the contents of the Remote Shared Object used in the sample .NET application switch to the Messaging Server tab in the Management Console, select the Chat node in the tree, then select the Shared Objects tab. As the clients send data, the console shows the internal state of the shared object.

Exactly the same approach and APIs are applicable if you build Android and iOS mobile applications. I plan to write a similar post demonstrating cross platform connectivity and messaging between .NET and Android and iOS clients.

Here’s a brief video showing the example in action:

Transcoding audio and video from browsers and devices

In addition to being a remoting and data management server, WebORB is also a powerful data/media server. It includes an implementation of the RTMP protocol which enables client supporting the protocol to transmit data messages or audio/video data between the client app and the server. One of the examples of data messaging is support for Remote Shared Objects. As for audio and video, any Flex or Flash client, running either in a browser or on a mobile device, can publish a video stream from the camera and audio stream from the microphone and the server will either record the stream or rebroadcast it for others to receive. A frequent request we received was for an ability to transcode the published streams on the server into other formats. We exposed the API enabling that feature in version 4.4 of WebORB for .NET. To see a concrete example for this feature, please see the WebORB and Speex codec article. The article includes the information about the APIs as well as a complete project for converting published speex data into a .wav file.

New samples fro WebORB Messaging

I’ve posted three new samples for WebORB Messaging. Each is designed to show how to set up and use a given feature in the most basic way, so that you can get started easily.

  1. Simple text chat: Shows instances of the same client-side app sharing information using a Remote Shared Object.
  2. Even simpler text chat: Shows instances of the same client-side app sharing information using Publish-Subscribe.
  3. Data Push: Server CPU Usage via Remote Shared Object (RSO): Shows server-side code pushing data to (any client) using a Remote Shared Object.

Happy coding!

:)

New samples: WebORB Data Management (WDM) for Flex (WDMF)

Most of these samples are minor variations of our CEO Mark Piller’s previous WDMF samples, which were installed with WebORB 4.x for .NET. These new versions include minor bug fixes, additional comments, and (most importantly) they are hosted on our Internet server, so that anyone, anywhere, can run them. Each sample has a descriptive web page, including a list of pre-requisites, key points, things to try, references, and links to any related screencasts.

The new samples are:

All of the samples share the same FoodAndDrinks database on our Web server, and so do all users. That’s realistic, but it also means that if you add a record to the database, it’s there fore everyone else to see, too. Likewise, if you delete a record (or all of the records), it will be deleted from the common database. We expect to deal with this by refreshing the database daily, but still…please play nicely.

If you’re using WebORB for .NET, but you’re not yet using WDM for Flex despite needing to access server-side data, then I encourage you to check out the first sample (at least). Watch its screencast and see what you’re missing.

Whee! :)

WebORB for .NET Remoting: even more samples

Here are six new samples, each describing a single aspect of Remoting (that is, the use of remote procedure calls) from a Flex client to a .NET service using WebORB 4.x for .NET. The name of each sample, below, links to a descriptive Web page, in which the running sample is embedded, and from which code (for both client and server) can be downloaded.

Custom serializer

Binding data grid to array result

Collection mapping with WebORBArrayCollection (class)

Collection mapping with IWebORBArrayCollection (interface)

ReturnType of DataTable’s records*

ReturnType of DataSet’s records*

With these basic Remoting samples out of the way, I’m going to switch my focus over to creating more WDMF samples.

Happy coding!   :)

— Jim

* At the time I posted these samples, the samples marked with an asterisk didn’t work, because I couldn’t update a DLL on the Midnight Coders’ “examples” server. When I can update the DLL, I’ll verify that the samples are working, and remove this comment.

WebORB for .NET Remoting: more samples

Gentlepersons,

I’ve recently posted nine more new samples on basic remoting (that is, making remote procedure calls) from Flex clients to .NET services using WebORB for .NET 4.x.

Each sample is accompanied by a web page that

  • describes the sample,
  • lists its key points,
  • lists things to try for yourself,
  • provides links to that sample’s code,
  • provides references to relevant documentation and supporting information,
  • embeds the running sample, and
  • embeds any screencasts that walk through the sample.

I have not yet made screencasts for these new samples, however.

These nine new samples, while still very basic, should be studied only after the four “Hello, World!” samples are understood, because those samples present the most basic fundamentals of using WebORB.

Here are the nine new samples:

Each sample’s web page has a section labeled “Errata,” describing known problems with the samples…so please let me know if you find any errors in them (jim@themidnightcoders.com).

BTW, a previous blog post, announcing the first of our new samples/screencasts, have emerged as a top result when using Google to search for “WebORB”. That’s encouraging.

Thanks!

— Jim :)